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