ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\Xml\Deserializer Namespace Reference

Data Structures

class  EnumTest
 
class  KeyValueTest
 
class  RepeatingElementsTest
 

Functions

 keyValue (Reader $reader, $namespace=null)
 This class provides a number of 'deserializer' helper functions. More...
 
 enum (Reader $reader, $namespace=null)
 The 'enum' deserializer parses elements into a simple list without values or attributes. More...
 
 valueObject (Reader $reader, $className, $namespace)
 The valueObject deserializer turns an xml element into a PHP object of a specific class. More...
 
 repeatingElements (Reader $reader, $childElementName)
 This deserializer helps you deserialize xml structures that look like this: More...
 

Function Documentation

◆ enum()

Sabre\Xml\Deserializer\enum ( Reader  $reader,
  $namespace = null 
)

The 'enum' deserializer parses elements into a simple list without values or attributes.

For example, Elements will parse:

<?xml version="1.0"? > <s:root xmlns:s="http://sabredav.org/ns"> <s:elem1 /> <s:elem2 /> <s:elem3 /> <s:elem4>content</s:elem4> <s:elem5 attr="val" /> </s:root>

Into:

[ "{http://sabredav.org/ns}elem1", "{http://sabredav.org/ns}elem2", "{http://sabredav.org/ns}elem3", "{http://sabredav.org/ns}elem4", "{http://sabredav.org/ns}elem5", ];

This is useful for 'enum'-like structures.

If the $namespace argument is specified, it will strip the namespace for all elements that match that.

For example,

enum($reader, 'http://sabredav.org/ns')

would return:

[ "elem1", "elem2", "elem3", "elem4", "elem5", ];

Parameters
Reader$reader
string$namespace
Returns
string[]

Definition at line 140 of file functions.php.

140 {
141
142 // If there's no children, we don't do anything.
143 if ($reader->isEmptyElement) {
144 $reader->next();
145 return [];
146 }
147 $reader->read();
148 $currentDepth = $reader->depth;
149
150 $values = [];
151 do {
152
153 if ($reader->nodeType !== Reader::ELEMENT) {
154 continue;
155 }
156 if (!is_null($namespace) && $namespace === $reader->namespaceURI) {
157 $values[] = $reader->localName;
158 } else {
159 $values[] = $reader->getClark();
160 }
161
162 } while ($reader->depth >= $currentDepth && $reader->next());
163
164 $reader->next();
165 return $values;
166
167}
if($err=$client->getError()) $namespace
$values

References $namespace, $reader, and $values.

Referenced by Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp\xmlDeserialize(), and Sabre\Xml\Element\Elements\xmlDeserialize().

+ Here is the caller graph for this function:

◆ keyValue()

Sabre\Xml\Deserializer\keyValue ( Reader  $reader,
  $namespace = null 
)

This class provides a number of 'deserializer' helper functions.

These can be used to easily specify custom deserializers for specific XML elements.

You can either use these functions from within the $elementMap in the Service or Reader class, or you can call them from within your own deserializer functions. The 'keyValue' deserializer parses all child elements, and outputs them as a "key=>value" array.

For example, keyvalue will parse:

<?xml version="1.0"?> <s:root xmlns:s="http://sabredav.org/ns"> <s:elem1>value1</s:elem1> <s:elem2>value2</s:elem2> <s:elem3 /> </s:root>

Into:

[ "{http://sabredav.org/ns}elem1" => "value1", "{http://sabredav.org/ns}elem2" => "value2", "{http://sabredav.org/ns}elem3" => null, ];

If you specify the 'namespace' argument, the deserializer will remove the namespaces of the keys that match that namespace.

For example, if you call keyValue like this:

keyValue($reader, 'http://sabredav.org/ns')

it's output will instead be:

[ "elem1" => "value1", "elem2" => "value2", "elem3" => null, ];

Attributes will be removed from the top-level elements. If elements with the same name appear twice in the list, only the last one will be kept.

Parameters
Reader$reader
string$namespace
Returns
array

Definition at line 61 of file functions.php.

61 {
62
63 // If there's no children, we don't do anything.
64 if ($reader->isEmptyElement) {
65 $reader->next();
66 return [];
67 }
68
69 $values = [];
70
71 $reader->read();
72 do {
73
74 if ($reader->nodeType === Reader::ELEMENT) {
75 if ($namespace !== null && $reader->namespaceURI === $namespace) {
76 $values[$reader->localName] = $reader->parseCurrentElement()['value'];
77 } else {
78 $clark = $reader->getClark();
79 $values[$clark] = $reader->parseCurrentElement()['value'];
80 }
81 } else {
82 $reader->read();
83 }
84 } while ($reader->nodeType !== Reader::END_ELEMENT);
85
86 $reader->read();
87
88 return $values;
89
90}

References $namespace, $reader, and $values.

Referenced by Sabre\Xml\Deserializer\KeyValueTest\testKeyValue(), Sabre\Xml\Deserializer\KeyValueTest\testKeyValueLoop(), Sabre\DAV\Xml\Element\Sharee\xmlDeserialize(), Sabre\DAVACL\Xml\Request\AclPrincipalPropSetReport\xmlDeserialize(), Sabre\DAVACL\Xml\Request\PrincipalMatchReport\xmlDeserialize(), and Sabre\Xml\Element\KeyValue\xmlDeserialize().

+ Here is the caller graph for this function:

◆ repeatingElements()

Sabre\Xml\Deserializer\repeatingElements ( Reader  $reader,
  $childElementName 
)

This deserializer helps you deserialize xml structures that look like this:

<collection> ... ... ... </collection>

Many XML documents use patterns like that, and this deserializer allow you to get all the 'items' as an array.

In that previous example, you would register the deserializer as such:

$reader->elementMap['{}collection'] = function($reader) { return repeatingElements($reader, '{}item'); }

The repeatingElements deserializer simply returns everything as an array.

Parameters
Reader$reader
string$childElementNameElement name in clark-notation
Returns
array

Definition at line 241 of file functions.php.

241 {
242
243 if ($childElementName[0] !== '{') {
244 $childElementName = '{}' . $childElementName;
245 }
246 $result = [];
247
248 foreach ($reader->parseGetElements() as $element) {
249
250 if ($element['name'] === $childElementName) {
251 $result[] = $element['value'];
252 }
253
254 }
255
256 return $result;
257
258}
$result

References $reader, and $result.

Referenced by Sabre\Xml\Deserializer\RepeatingElementsTest\testRead().

+ Here is the caller graph for this function:

◆ valueObject()

Sabre\Xml\Deserializer\valueObject ( Reader  $reader,
  $className,
  $namespace 
)

The valueObject deserializer turns an xml element into a PHP object of a specific class.

This is primarily used by the mapValueObject function from the Service class, but it can also easily be used for more specific situations.

Parameters
Reader$reader
string$className
string$namespace
Returns
object

Definition at line 181 of file functions.php.

181 {
182
183 $valueObject = new $className();
184 if ($reader->isEmptyElement) {
185 $reader->next();
186 return $valueObject;
187 }
188
189 $defaultProperties = get_class_vars($className);
190
191 $reader->read();
192 do {
193
194 if ($reader->nodeType === Reader::ELEMENT && $reader->namespaceURI == $namespace) {
195
196 if (property_exists($valueObject, $reader->localName)) {
197 if (is_array($defaultProperties[$reader->localName])) {
198 $valueObject->{$reader->localName}[] = $reader->parseCurrentElement()['value'];
199 } else {
200 $valueObject->{$reader->localName} = $reader->parseCurrentElement()['value'];
201 }
202 } else {
203 // Ignore property
204 $reader->next();
205 }
206 } else {
207 $reader->read();
208 }
209 } while ($reader->nodeType !== Reader::END_ELEMENT);
210
211 $reader->read();
212 return $valueObject;
213
214}

References $namespace, and $reader.

Referenced by Sabre\Xml\Service\mapValueObject(), Sabre\XML\Deserializer\ValueObjectTest\testDeserializeValueObject(), Sabre\XML\Deserializer\ValueObjectTest\testDeserializeValueObjectAutoArray(), Sabre\XML\Deserializer\ValueObjectTest\testDeserializeValueObjectEmpty(), and Sabre\XML\Deserializer\ValueObjectTest\testDeserializeValueObjectIgnoredElement().

+ Here is the caller graph for this function: