1<?php
2
3namespace Sabre\Xml\Element;
4
5use Sabre\Xml;
6
7/**
8 * The Base XML element is the standard parser & generator that's used by the
9 * XML reader and writer.
10 *
11 * It spits out a simple PHP array structure during deserialization, that can
12 * also be directly injected back into Writer::write.
13 *
14 * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/).
15 * @author Evert Pot (http://evertpot.com/)
16 * @license http://sabre.io/license/ Modified BSD License
17 */
18class Base implements Xml\Element {
19
20    /**
21     * PHP value to serialize.
22     *
23     * @var mixed
24     */
25    protected $value;
26
27    /**
28     * Constructor
29     *
30     * @param mixed $value
31     */
32    function __construct($value = null) {
33
34        $this->value = $value;
35
36    }
37
38    /**
39     * The xmlSerialize metod is called during xml writing.
40     *
41     * Use the $writer argument to write its own xml serialization.
42     *
43     * An important note: do _not_ create a parent element. Any element
44     * implementing XmlSerializable should only ever write what's considered
45     * its 'inner xml'.
46     *
47     * The parent of the current element is responsible for writing a
48     * containing element.
49     *
50     * This allows serializers to be re-used for different element names.
51     *
52     * If you are opening new elements, you must also close them again.
53     *
54     * @param Writer $writer
55     * @return void
56     */
57    function xmlSerialize(Xml\Writer $writer) {
58
59        $writer->write($this->value);
60
61    }
62
63    /**
64     * The deserialize method is called during xml parsing.
65     *
66     * This method is called statictly, this is because in theory this method
67     * may be used as a type of constructor, or factory method.
68     *
69     * Often you want to return an instance of the current class, but you are
70     * free to return other data as well.
71     *
72     * Important note 2: You are responsible for advancing the reader to the
73     * next element. Not doing anything will result in a never-ending loop.
74     *
75     * If you just want to skip parsing for this element altogether, you can
76     * just call $reader->next();
77     *
78     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
79     * the next element.
80     *
81     * @param Xml\Reader $reader
82     * @return mixed
83     */
84    static function xmlDeserialize(Xml\Reader $reader) {
85
86        $subTree = $reader->parseInnerTree();
87        return $subTree;
88
89    }
90
91}
92