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 Boehler/** 8*a1a3b679SAndreas Boehler * The intention for this reader class, is to read past the end element. This 9*a1a3b679SAndreas Boehler * should trigger a ParseException 10*a1a3b679SAndreas Boehler * 11*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/). 12*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 13*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 14*a1a3b679SAndreas Boehler */ 15*a1a3b679SAndreas Boehlerclass Eater implements Xml\Element { 16*a1a3b679SAndreas Boehler 17*a1a3b679SAndreas Boehler /** 18*a1a3b679SAndreas Boehler * The serialize method is called during xml writing. 19*a1a3b679SAndreas Boehler * 20*a1a3b679SAndreas Boehler * It should use the $writer argument to encode this object into Xml. 21*a1a3b679SAndreas Boehler * 22*a1a3b679SAndreas Boehler * Important note: it is not needed to create the parent element. The 23*a1a3b679SAndreas Boehler * parent element is already created, and we only have to worry about 24*a1a3b679SAndreas Boehler * attributes, child elements and text (if any). 25*a1a3b679SAndreas Boehler * 26*a1a3b679SAndreas Boehler * Important note 2: If you are writing any new elements, you are also 27*a1a3b679SAndreas Boehler * responsible for closing them. 28*a1a3b679SAndreas Boehler * 29*a1a3b679SAndreas Boehler * @param Xml\Writer $writer 30*a1a3b679SAndreas Boehler * @return void 31*a1a3b679SAndreas Boehler */ 32*a1a3b679SAndreas Boehler function xmlSerialize(Xml\Writer $writer) { 33*a1a3b679SAndreas Boehler 34*a1a3b679SAndreas Boehler $writer->startElement('{http://sabredav.org/ns}elem1'); 35*a1a3b679SAndreas Boehler $writer->write('hiiii!'); 36*a1a3b679SAndreas Boehler $writer->endElement(); 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler } 39*a1a3b679SAndreas Boehler 40*a1a3b679SAndreas Boehler /** 41*a1a3b679SAndreas Boehler * The deserialize method is called during xml parsing. 42*a1a3b679SAndreas Boehler * 43*a1a3b679SAndreas Boehler * This method is called statictly, this is because in theory this method 44*a1a3b679SAndreas Boehler * may be used as a type of constructor, or factory method. 45*a1a3b679SAndreas Boehler * 46*a1a3b679SAndreas Boehler * Often you want to return an instance of the current class, but you are 47*a1a3b679SAndreas Boehler * free to return other data as well. 48*a1a3b679SAndreas Boehler * 49*a1a3b679SAndreas Boehler * Important note 2: You are responsible for advancing the reader to the 50*a1a3b679SAndreas Boehler * next element. Not doing anything will result in a never-ending loop. 51*a1a3b679SAndreas Boehler * 52*a1a3b679SAndreas Boehler * If you just want to skip parsing for this element altogether, you can 53*a1a3b679SAndreas Boehler * just call $reader->next(); 54*a1a3b679SAndreas Boehler * 55*a1a3b679SAndreas Boehler * $reader->parseSubTree() will parse the entire sub-tree, and advance to 56*a1a3b679SAndreas Boehler * the next element. 57*a1a3b679SAndreas Boehler * 58*a1a3b679SAndreas Boehler * @param Xml\Reader $reader 59*a1a3b679SAndreas Boehler * @return mixed 60*a1a3b679SAndreas Boehler */ 61*a1a3b679SAndreas Boehler static function xmlDeserialize(Xml\Reader $reader) { 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler $reader->next(); 64*a1a3b679SAndreas Boehler 65*a1a3b679SAndreas Boehler $count = 1; 66*a1a3b679SAndreas Boehler while ($count) { 67*a1a3b679SAndreas Boehler 68*a1a3b679SAndreas Boehler $reader->read(); 69*a1a3b679SAndreas Boehler if ($reader->nodeType === $reader::END_ELEMENT) { 70*a1a3b679SAndreas Boehler $count--; 71*a1a3b679SAndreas Boehler } 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler } 74*a1a3b679SAndreas Boehler $reader->read(); 75*a1a3b679SAndreas Boehler 76*a1a3b679SAndreas Boehler } 77*a1a3b679SAndreas Boehler 78*a1a3b679SAndreas Boehler} 79