1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Xml\Request; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\Xml\Reader; 6*a1a3b679SAndreas Boehleruse Sabre\Xml\XmlDeserializable; 7*a1a3b679SAndreas Boehleruse Sabre\CalDAV\Plugin; 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehler/** 10*a1a3b679SAndreas Boehler * Share POST request parser 11*a1a3b679SAndreas Boehler * 12*a1a3b679SAndreas Boehler * This class parses the share POST request, as defined in: 13*a1a3b679SAndreas Boehler * 14*a1a3b679SAndreas Boehler * http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-sharing.txt 15*a1a3b679SAndreas Boehler * 16*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/) 17*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 18*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 19*a1a3b679SAndreas Boehler */ 20*a1a3b679SAndreas Boehlerclass Share implements XmlDeserializable { 21*a1a3b679SAndreas Boehler 22*a1a3b679SAndreas Boehler /** 23*a1a3b679SAndreas Boehler * The list of new people added or updated. 24*a1a3b679SAndreas Boehler * 25*a1a3b679SAndreas Boehler * Every element has the following keys: 26*a1a3b679SAndreas Boehler * 1. href - An email address 27*a1a3b679SAndreas Boehler * 2. commonName - Some name 28*a1a3b679SAndreas Boehler * 3. summary - An optional description of the share 29*a1a3b679SAndreas Boehler * 4. readOnly - true or false 30*a1a3b679SAndreas Boehler * 31*a1a3b679SAndreas Boehler * @var array 32*a1a3b679SAndreas Boehler */ 33*a1a3b679SAndreas Boehler public $set = []; 34*a1a3b679SAndreas Boehler 35*a1a3b679SAndreas Boehler /** 36*a1a3b679SAndreas Boehler * List of people removed from the share list. 37*a1a3b679SAndreas Boehler * 38*a1a3b679SAndreas Boehler * The list is a flat list of email addresses (including mailto:). 39*a1a3b679SAndreas Boehler * 40*a1a3b679SAndreas Boehler * @var array 41*a1a3b679SAndreas Boehler */ 42*a1a3b679SAndreas Boehler public $remove = []; 43*a1a3b679SAndreas Boehler 44*a1a3b679SAndreas Boehler /** 45*a1a3b679SAndreas Boehler * Constructor 46*a1a3b679SAndreas Boehler * 47*a1a3b679SAndreas Boehler * @param array $set 48*a1a3b679SAndreas Boehler * @param array $remove 49*a1a3b679SAndreas Boehler */ 50*a1a3b679SAndreas Boehler function __construct(array $set, array $remove) { 51*a1a3b679SAndreas Boehler 52*a1a3b679SAndreas Boehler $this->set = $set; 53*a1a3b679SAndreas Boehler $this->remove = $remove; 54*a1a3b679SAndreas Boehler 55*a1a3b679SAndreas Boehler } 56*a1a3b679SAndreas Boehler 57*a1a3b679SAndreas Boehler /** 58*a1a3b679SAndreas Boehler * The deserialize method is called during xml parsing. 59*a1a3b679SAndreas Boehler * 60*a1a3b679SAndreas Boehler * This method is called statictly, this is because in theory this method 61*a1a3b679SAndreas Boehler * may be used as a type of constructor, or factory method. 62*a1a3b679SAndreas Boehler * 63*a1a3b679SAndreas Boehler * Often you want to return an instance of the current class, but you are 64*a1a3b679SAndreas Boehler * free to return other data as well. 65*a1a3b679SAndreas Boehler * 66*a1a3b679SAndreas Boehler * You are responsible for advancing the reader to the next element. Not 67*a1a3b679SAndreas Boehler * doing anything will result in a never-ending loop. 68*a1a3b679SAndreas Boehler * 69*a1a3b679SAndreas Boehler * If you just want to skip parsing for this element altogether, you can 70*a1a3b679SAndreas Boehler * just call $reader->next(); 71*a1a3b679SAndreas Boehler * 72*a1a3b679SAndreas Boehler * $reader->parseInnerTree() will parse the entire sub-tree, and advance to 73*a1a3b679SAndreas Boehler * the next element. 74*a1a3b679SAndreas Boehler * 75*a1a3b679SAndreas Boehler * @param Reader $reader 76*a1a3b679SAndreas Boehler * @return mixed 77*a1a3b679SAndreas Boehler */ 78*a1a3b679SAndreas Boehler static function xmlDeserialize(Reader $reader) { 79*a1a3b679SAndreas Boehler 80*a1a3b679SAndreas Boehler $elems = $reader->parseInnerTree([ 81*a1a3b679SAndreas Boehler '{' . Plugin::NS_CALENDARSERVER . '}set' => 'Sabre\\Xml\\Element\\KeyValue', 82*a1a3b679SAndreas Boehler '{' . Plugin::NS_CALENDARSERVER . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', 83*a1a3b679SAndreas Boehler ]); 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler $set = []; 86*a1a3b679SAndreas Boehler $remove = []; 87*a1a3b679SAndreas Boehler 88*a1a3b679SAndreas Boehler foreach ($elems as $elem) { 89*a1a3b679SAndreas Boehler switch ($elem['name']) { 90*a1a3b679SAndreas Boehler 91*a1a3b679SAndreas Boehler case '{' . Plugin::NS_CALENDARSERVER . '}set' : 92*a1a3b679SAndreas Boehler $sharee = $elem['value']; 93*a1a3b679SAndreas Boehler 94*a1a3b679SAndreas Boehler $sumElem = '{' . Plugin::NS_CALENDARSERVER . '}summary'; 95*a1a3b679SAndreas Boehler $commonName = '{' . Plugin::NS_CALENDARSERVER . '}common-name'; 96*a1a3b679SAndreas Boehler 97*a1a3b679SAndreas Boehler $set[] = [ 98*a1a3b679SAndreas Boehler 'href' => $sharee['{DAV:}href'], 99*a1a3b679SAndreas Boehler 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, 100*a1a3b679SAndreas Boehler 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, 101*a1a3b679SAndreas Boehler 'readOnly' => !array_key_exists('{' . Plugin::NS_CALENDARSERVER . '}read-write', $sharee), 102*a1a3b679SAndreas Boehler ]; 103*a1a3b679SAndreas Boehler break; 104*a1a3b679SAndreas Boehler 105*a1a3b679SAndreas Boehler case '{' . Plugin::NS_CALENDARSERVER . '}remove' : 106*a1a3b679SAndreas Boehler $remove[] = $elem['value']['{DAV:}href']; 107*a1a3b679SAndreas Boehler break; 108*a1a3b679SAndreas Boehler 109*a1a3b679SAndreas Boehler } 110*a1a3b679SAndreas Boehler } 111*a1a3b679SAndreas Boehler 112*a1a3b679SAndreas Boehler return new self($set, $remove); 113*a1a3b679SAndreas Boehler 114*a1a3b679SAndreas Boehler } 115*a1a3b679SAndreas Boehler 116*a1a3b679SAndreas Boehler} 117