ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Struct.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
58{
59
60 // {{{ setNativeValue()
61
67 protected function setNativeValue($value)
68 {
69 if (!is_array($value)) {
70 throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Struct from type \'%s\'.', gettype($nativeValue)));
71 }
72 parent::setNativeValue($value);
73 }
74
75 // }}}
76 // {{{ constructor
77
83 public function __construct($nativeValue)
84 {
85 $this->setNativeValue($nativeValue);
86 }
87
88 // }}}
89 // {{{ encode()
90
96 public function encode()
97 {
98 $result = '<struct>';
99 foreach($this->getNativeValue() as $name => $element) {
100 $result .= '<member>';
101 $result .= '<name>';
102 $result .= strtr($name, array('&' => '&amp;', '<' => '&lt;', '>' => '&gt;'));
103 $result .= '</name>';
104 $result .= '<value>';
105 $result .= ($element instanceof XML_RPC2_Backend_Php_Value) ?
106 $element->encode() :
108 $result .= '</value>';
109 $result .= '</member>';
110 }
111 $result .= '</struct>';
112 return $result;
113 }
114
115 // }}}
116 // {{{ decode()
117
123 public static function decode($xml)
124 {
125 // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
126 // xpath is used both in an element and in one of its children
127 $xml = simplexml_load_string($xml->asXML());
128 $values = $xml->xpath('/value/struct/member');
129 $result = array();
130 foreach (array_keys($values) as $i) {
131 $result[(string) $values[$i]->name] = XML_RPC2_Backend_Php_Value::createFromDecode($values[$i]->value)->getNativeValue();
132 }
133 return $result;
134 }
135
136 // }}}
137
138}
139
140?>
$result
__construct($nativeValue)
Constructor.
Definition: Struct.php:83
encode()
Encode the instance into XML, for transport.
Definition: Struct.php:96
static decode($xml)
Decode transport XML and set the instance value accordingly.
Definition: Struct.php:123
setNativeValue($value)
nativeValue property setter
Definition: Struct.php:67
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