1<?php
2
3namespace Sabre\Xml\Element;
4
5use Sabre\Xml;
6use Sabre\Xml\Deserializer;
7use Sabre\Xml\Serializer;
8
9/**
10 * 'Elements' is a simple list of elements, without values or attributes.
11 * For example, Elements will parse:
12 *
13 * <?xml version="1.0"?>
14 * <s:root xmlns:s="http://sabredav.org/ns">
15 *   <s:elem1 />
16 *   <s:elem2 />
17 *   <s:elem3 />
18 *   <s:elem4>content</s:elem4>
19 *   <s:elem5 attr="val" />
20 * </s:root>
21 *
22 * Into:
23 *
24 * [
25 *   "{http://sabredav.org/ns}elem1",
26 *   "{http://sabredav.org/ns}elem2",
27 *   "{http://sabredav.org/ns}elem3",
28 *   "{http://sabredav.org/ns}elem4",
29 *   "{http://sabredav.org/ns}elem5",
30 * ];
31 *
32 * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
33 * @author Evert Pot (http://evertpot.com/)
34 * @license http://sabre.io/license/ Modified BSD License
35 */
36class Elements implements Xml\Element {
37
38    /**
39     * Value to serialize
40     *
41     * @var array
42     */
43    protected $value;
44
45    /**
46     * Constructor
47     *
48     * @param array $value
49     */
50    function __construct(array $value = []) {
51
52        $this->value = $value;
53
54    }
55
56    /**
57     * The xmlSerialize metod is called during xml writing.
58     *
59     * Use the $writer argument to write its own xml serialization.
60     *
61     * An important note: do _not_ create a parent element. Any element
62     * implementing XmlSerializble should only ever write what's considered
63     * its 'inner xml'.
64     *
65     * The parent of the current element is responsible for writing a
66     * containing element.
67     *
68     * This allows serializers to be re-used for different element names.
69     *
70     * If you are opening new elements, you must also close them again.
71     *
72     * @param Writer $writer
73     * @return void
74     */
75    function xmlSerialize(Xml\Writer $writer) {
76
77        Serializer\enum($writer, $this->value);
78
79    }
80
81    /**
82     * The deserialize method is called during xml parsing.
83     *
84     * This method is called statictly, this is because in theory this method
85     * may be used as a type of constructor, or factory method.
86     *
87     * Often you want to return an instance of the current class, but you are
88     * free to return other data as well.
89     *
90     * Important note 2: You are responsible for advancing the reader to the
91     * next element. Not doing anything will result in a never-ending loop.
92     *
93     * If you just want to skip parsing for this element altogether, you can
94     * just call $reader->next();
95     *
96     * $reader->parseSubTree() will parse the entire sub-tree, and advance to
97     * the next element.
98     *
99     * @param Xml\Reader $reader
100     * @return mixed
101     */
102    static function xmlDeserialize(Xml\Reader $reader) {
103
104        return Deserializer\enum($reader);
105
106    }
107
108}
109