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