xref: /plugin/davcal/vendor/sabre/xml/tests/Sabre/Xml/Element/Mock.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\Xml\Element;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\Xml;
6*a1a3b679SAndreas Boehler
7*a1a3b679SAndreas Boehlerclass Mock implements Xml\Element {
8*a1a3b679SAndreas Boehler
9*a1a3b679SAndreas Boehler    /**
10*a1a3b679SAndreas Boehler     * The serialize method is called during xml writing.
11*a1a3b679SAndreas Boehler     *
12*a1a3b679SAndreas Boehler     * It should use the $writer argument to encode this object into XML.
13*a1a3b679SAndreas Boehler     *
14*a1a3b679SAndreas Boehler     * Important note: it is not needed to create the parent element. The
15*a1a3b679SAndreas Boehler     * parent element is already created, and we only have to worry about
16*a1a3b679SAndreas Boehler     * attributes, child elements and text (if any).
17*a1a3b679SAndreas Boehler     *
18*a1a3b679SAndreas Boehler     * Important note 2: If you are writing any new elements, you are also
19*a1a3b679SAndreas Boehler     * responsible for closing them.
20*a1a3b679SAndreas Boehler     *
21*a1a3b679SAndreas Boehler     * @param Xml\Writer $writer
22*a1a3b679SAndreas Boehler     * @return void
23*a1a3b679SAndreas Boehler     */
24*a1a3b679SAndreas Boehler    function xmlSerialize(Xml\Writer $writer) {
25*a1a3b679SAndreas Boehler
26*a1a3b679SAndreas Boehler        $writer->startElement('{http://sabredav.org/ns}elem1');
27*a1a3b679SAndreas Boehler        $writer->write('hiiii!');
28*a1a3b679SAndreas Boehler        $writer->endElement();
29*a1a3b679SAndreas Boehler
30*a1a3b679SAndreas Boehler    }
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler    /**
33*a1a3b679SAndreas Boehler     * The deserialize method is called during xml parsing.
34*a1a3b679SAndreas Boehler     *
35*a1a3b679SAndreas Boehler     * This method is called statictly, this is because in theory this method
36*a1a3b679SAndreas Boehler     * may be used as a type of constructor, or factory method.
37*a1a3b679SAndreas Boehler     *
38*a1a3b679SAndreas Boehler     * Often you want to return an instance of the current class, but you are
39*a1a3b679SAndreas Boehler     * free to return other data as well.
40*a1a3b679SAndreas Boehler     *
41*a1a3b679SAndreas Boehler     * Important note 2: You are responsible for advancing the reader to the
42*a1a3b679SAndreas Boehler     * next element. Not doing anything will result in a never-ending loop.
43*a1a3b679SAndreas Boehler     *
44*a1a3b679SAndreas Boehler     * If you just want to skip parsing for this element altogether, you can
45*a1a3b679SAndreas Boehler     * just call $reader->next();
46*a1a3b679SAndreas Boehler     *
47*a1a3b679SAndreas Boehler     * $reader->parseSubTree() will parse the entire sub-tree, and advance to
48*a1a3b679SAndreas Boehler     * the next element.
49*a1a3b679SAndreas Boehler     *
50*a1a3b679SAndreas Boehler     * @param Xml\Reader $reader
51*a1a3b679SAndreas Boehler     * @return mixed
52*a1a3b679SAndreas Boehler     */
53*a1a3b679SAndreas Boehler    static function xmlDeserialize(Xml\Reader $reader) {
54*a1a3b679SAndreas Boehler
55*a1a3b679SAndreas Boehler        $reader->next();
56*a1a3b679SAndreas Boehler        return 'foobar';
57*a1a3b679SAndreas Boehler
58*a1a3b679SAndreas Boehler    }
59*a1a3b679SAndreas Boehler
60*a1a3b679SAndreas Boehler}
61