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 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 * @return mixed 39 */ 40 public 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 46 return []; 47 } 48 49 $values = []; 50 $reader->read(); 51 52 do { 53 if (SabreXml\Reader::ELEMENT === $reader->nodeType) { 54 $name = $reader->localName; 55 $values[$name] = $reader->parseCurrentElement()['value']; 56 } else { 57 $reader->read(); 58 } 59 } while (SabreXml\Reader::END_ELEMENT !== $reader->nodeType); 60 61 $reader->read(); 62 63 return $values; 64 } 65} 66