ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Array.php
Go to the documentation of this file.
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
4
5// LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{
6
40// }}}
41
42// dependencies {{{
43require_once 'XML/RPC2/Exception.php';
44require_once 'XML/RPC2/Backend/Php/Value.php';
45// }}}
46
54{
55
56 // {{{ setNativeValue()
57
63 protected function setNativeValue($value)
64 {
65 if (!is_array($value)) {
66 throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Value_Array from type \'%s\'.', gettype($nativeValue)));
67 }
68 parent::setNativeValue($value);
69 }
70
71 // }}}
72 // {{{ constructor
73
79 public function __construct($nativeValue)
80 {
81 $this->setNativeValue($nativeValue);
82 }
83
84 // }}}
85 // {{{ encode()
86
92 public function encode()
93 {
94 $result = '<array><data>';
95 foreach($this->getNativeValue() as $element) {
96 $result .= '<value>';
97 $result .= ($element instanceof XML_RPC2_Backend_Php_Value) ?
98 $element->encode() :
100 $result .= '</value>';
101 }
102 $result .= '</data></array>';
103 return $result;
104 }
105
106 // }}}
107 // {{{ decode()
108
114 public static function decode($xml)
115 {
116 // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
117 // xpath is used both in an element and in one of its children
118 $xml = simplexml_load_string($xml->asXML());
119 $values = $xml->xpath('/value/array/data/value');
120 $result = array();
121 foreach (array_keys($values) as $i) {
122 $result[] = XML_RPC2_Backend_Php_Value::createFromDecode($values[$i])->getNativeValue();
123 }
124 return $result;
125 }
126
127 // }}}
128
129}
130
131?>
$result
__construct($nativeValue)
Constructor.
Definition: Array.php:79
static decode($xml)
Decode transport XML and set the instance value accordingly.
Definition: Array.php:114
encode()
Encode the instance into XML, for transport.
Definition: Array.php:92
setNativeValue($value)
nativeValue property setter
Definition: Array.php:63
static createFromNative($nativeValue, $explicitType=null)
Choose a XML_RPC2_Value subclass appropriate for the given value and create it.
Definition: Value.php:123
static createFromDecode($simpleXML)
Decode an encoded value and build the applicable XML_RPC2_Value subclass.
Definition: Value.php:215
getNativeValue()
nativeValue property getter
Definition: Value.php:76