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