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
Elements.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace AmeliaVendor\Sabre\Xml\Element; |
| 5 | |
| 6 | use AmeliaVendor\Sabre\Xml; |
| 7 | use AmeliaVendor\Sabre\Xml\Deserializer; |
| 8 | use AmeliaVendor\Sabre\Xml\Serializer; |
| 9 | /** |
| 10 | * 'Elements' is a simple list of elements, without values or attributes. |
| 11 | * For example, Elements will parse:. |
| 12 | * |
| 13 | * <?xml version="1.0"?> |
| 14 | * <s:root xmlns:s="http://sabredav.org/ns"> |
| 15 | * <s:elem1 /> |
| 16 | * <s:elem2 /> |
| 17 | * <s:elem3 /> |
| 18 | * <s:elem4>content</s:elem4> |
| 19 | * <s:elem5 attr="val" /> |
| 20 | * </s:root> |
| 21 | * |
| 22 | * Into: |
| 23 | * |
| 24 | * [ |
| 25 | * "{http://sabredav.org/ns}elem1", |
| 26 | * "{http://sabredav.org/ns}elem2", |
| 27 | * "{http://sabredav.org/ns}elem3", |
| 28 | * "{http://sabredav.org/ns}elem4", |
| 29 | * "{http://sabredav.org/ns}elem5", |
| 30 | * ]; |
| 31 | * |
| 32 | * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/). |
| 33 | * @author Evert Pot (http://evertpot.com/) |
| 34 | * @license http://sabre.io/license/ Modified BSD License |
| 35 | */ |
| 36 | class Elements implements Xml\Element |
| 37 | { |
| 38 | /** |
| 39 | * Value to serialize. |
| 40 | * |
| 41 | * @var array<int, mixed> |
| 42 | */ |
| 43 | protected array $value; |
| 44 | /** |
| 45 | * Constructor. |
| 46 | * |
| 47 | * @param array<int, mixed> $value |
| 48 | */ |
| 49 | public function __construct(array $value = []) |
| 50 | { |
| 51 | $this->value = $value; |
| 52 | } |
| 53 | /** |
| 54 | * The xmlSerialize method is called during xml writing. |
| 55 | * |
| 56 | * Use the $writer argument to write its own xml serialization. |
| 57 | * |
| 58 | * An important note: do _not_ create a parent element. Any element |
| 59 | * implementing XmlSerializable should only ever write what's considered |
| 60 | * its 'inner xml'. |
| 61 | * |
| 62 | * The parent of the current element is responsible for writing a |
| 63 | * containing element. |
| 64 | * |
| 65 | * This allows serializers to be re-used for different element names. |
| 66 | * |
| 67 | * If you are opening new elements, you must also close them again. |
| 68 | */ |
| 69 | public function xmlSerialize(Xml\Writer $writer): void |
| 70 | { |
| 71 | \AmeliaVendor\Sabre\Xml\Serializer\enum($writer, $this->value); |
| 72 | } |
| 73 | /** |
| 74 | * The deserialize method is called during xml parsing. |
| 75 | * |
| 76 | * This method is called statically, this is because in theory this method |
| 77 | * may be used as a type of constructor, or factory method. |
| 78 | * |
| 79 | * Often you want to return an instance of the current class, but you are |
| 80 | * free to return other data as well. |
| 81 | * |
| 82 | * Important note 2: You are responsible for advancing the reader to the |
| 83 | * next element. Not doing anything will result in a never-ending loop. |
| 84 | * |
| 85 | * If you just want to skip parsing for this element altogether, you can |
| 86 | * just call $reader->next(); |
| 87 | * |
| 88 | * $reader->parseSubTree() will parse the entire sub-tree, and advance to |
| 89 | * the next element. |
| 90 | * |
| 91 | * @return string[] |
| 92 | */ |
| 93 | public static function xmlDeserialize(Xml\Reader $reader) |
| 94 | { |
| 95 | return \AmeliaVendor\Sabre\Xml\Deserializer\enum($reader); |
| 96 | } |
| 97 | } |