1<?php 2 3namespace Sabre\VObject\Parser\XML\Element; 4 5use 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 */ 16class KeyValue extends SabreXml\Element\KeyValue { 17 18 /** 19 * The deserialize method is called during xml parsing. 20 * 21 * This method is called staticly, 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 * @return mixed 39 */ 40 static function xmlDeserialize(SabreXml\Reader $reader) { 41 42 // If there's no children, we don't do anything. 43 if ($reader->isEmptyElement) { 44 $reader->next(); 45 return []; 46 } 47 48 $values = []; 49 $reader->read(); 50 51 do { 52 53 if ($reader->nodeType === SabreXml\Reader::ELEMENT) { 54 55 $name = $reader->localName; 56 $values[$name] = $reader->parseCurrentElement()['value']; 57 58 } else { 59 $reader->read(); 60 } 61 62 } while ($reader->nodeType !== SabreXml\Reader::END_ELEMENT); 63 64 $reader->read(); 65 66 return $values; 67 68 } 69 70} 71