|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Sabre\XML\Element; |
| 4 | + |
| 5 | +use 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) 2007-2013 Rooftop Solutions. All rights reserved. |
| 12 | + * @author Evert Pot (http://www.rooftopsolutions.nl/) |
| 13 | + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License |
| 14 | + */ |
| 15 | +class 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 | + public function serializeXml(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 public function deserializeXml(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 | +} |
0 commit comments