KeyValue.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject\Parser\XML\Element; |
| 4 | |
| 5 | use AmeliaVendor\Sabre\Xml as SabreXml; |
| 6 | |
| 7 | /** |
| 8 | * Our own sabre/xml key-value element. |
| 9 | * |
| 10 | * It just removes the clark notation. |
| 11 | * |
| 12 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 13 | * @author Ivan Enderlin |
| 14 | * @license http://sabre.io/license/ Modified BSD License |
| 15 | */ |
| 16 | class KeyValue extends SabreXml\Element\KeyValue |
| 17 | { |
| 18 | /** |
| 19 | * The deserialize method is called during xml parsing. |
| 20 | * |
| 21 | * This method is called statically, this is because in theory this method |
| 22 | * may be used as a type of constructor, or factory method. |
| 23 | * |
| 24 | * Often you want to return an instance of the current class, but you are |
| 25 | * free to return other data as well. |
| 26 | * |
| 27 | * Important note 2: You are responsible for advancing the reader to the |
| 28 | * next element. Not doing anything will result in a never-ending loop. |
| 29 | * |
| 30 | * If you just want to skip parsing for this element altogether, you can |
| 31 | * just call $reader->next(); |
| 32 | * |
| 33 | * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
| 34 | * the next element. |
| 35 | * |
| 36 | * @param XML\Reader $reader |
| 37 | */ |
| 38 | public static function xmlDeserialize(SabreXml\Reader $reader): array |
| 39 | { |
| 40 | // If there's no children, we don't do anything. |
| 41 | if ($reader->isEmptyElement) { |
| 42 | $reader->next(); |
| 43 | |
| 44 | return []; |
| 45 | } |
| 46 | |
| 47 | $values = []; |
| 48 | $reader->read(); |
| 49 | |
| 50 | do { |
| 51 | if (SabreXml\Reader::ELEMENT === $reader->nodeType) { |
| 52 | $name = $reader->localName; |
| 53 | $values[$name] = $reader->parseCurrentElement()['value']; |
| 54 | } else { |
| 55 | $reader->read(); |
| 56 | } |
| 57 | } while (SabreXml\Reader::END_ELEMENT !== $reader->nodeType); |
| 58 | |
| 59 | $reader->read(); |
| 60 | |
| 61 | return $values; |
| 62 | } |
| 63 | } |
| 64 |