1<?php 2 3namespace Sabre\CalDAV\Xml\Filter; 4 5use Sabre\Xml\Reader; 6use Sabre\Xml\XmlDeserializable; 7use Sabre\DAV\Exception\BadRequest; 8use Sabre\CalDAV\Plugin; 9use Sabre\VObject\DateTimeParser; 10 11/** 12 * PropFilter parser. 13 * 14 * This class parses the {urn:ietf:params:xml:ns:caldav}prop-filter XML 15 * element, as defined in: 16 * 17 * https://tools.ietf.org/html/rfc4791#section-9.7.2 18 * 19 * The result will be spit out as an array. 20 * 21 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 22 * @author Evert Pot (http://www.rooftopsolutions.nl/) 23 * @license http://sabre.io/license/ Modified BSD License 24 */ 25class PropFilter implements XmlDeserializable { 26 27 /** 28 * The deserialize method is called during xml parsing. 29 * 30 * This method is called statictly, this is because in theory this method 31 * may be used as a type of constructor, or factory method. 32 * 33 * Often you want to return an instance of the current class, but you are 34 * free to return other data as well. 35 * 36 * You are responsible for advancing the reader to the next element. Not 37 * doing anything will result in a never-ending loop. 38 * 39 * If you just want to skip parsing for this element altogether, you can 40 * just call $reader->next(); 41 * 42 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to 43 * the next element. 44 * 45 * @param Reader $reader 46 * @return mixed 47 */ 48 static function xmlDeserialize(Reader $reader) { 49 50 $result = [ 51 'name' => null, 52 'is-not-defined' => false, 53 'param-filters' => [], 54 'text-match' => null, 55 'time-range' => false, 56 ]; 57 58 $att = $reader->parseAttributes(); 59 $result['name'] = $att['name']; 60 61 $elems = $reader->parseInnerTree(); 62 63 if (is_array($elems)) foreach ($elems as $elem) { 64 65 switch ($elem['name']) { 66 67 case '{' . Plugin::NS_CALDAV . '}param-filter' : 68 $result['param-filters'][] = $elem['value']; 69 break; 70 case '{' . Plugin::NS_CALDAV . '}is-not-defined' : 71 $result['is-not-defined'] = true; 72 break; 73 case '{' . Plugin::NS_CALDAV . '}time-range' : 74 $result['time-range'] = [ 75 'start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, 76 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null, 77 ]; 78 if ($result['time-range']['start'] && $result['time-range']['end'] && $result['time-range']['end'] <= $result['time-range']['start']) { 79 throw new BadRequest('The end-date must be larger than the start-date'); 80 } 81 break; 82 case '{' . Plugin::NS_CALDAV . '}text-match' : 83 $result['text-match'] = [ 84 'negate-condition' => isset($elem['attributes']['negate-condition']) && $elem['attributes']['negate-condition'] === 'yes', 85 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;ascii-casemap', 86 'value' => $elem['value'], 87 ]; 88 break; 89 90 } 91 92 } 93 94 return $result; 95 96 } 97 98} 99