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\Xml\Element\KeyValue; 8*a1a3b679SAndreas Boehleruse Sabre\DAV\Exception\BadRequest; 9*a1a3b679SAndreas Boehleruse Sabre\CalDAV\Plugin; 10*a1a3b679SAndreas Boehleruse Sabre\CalDAV\SharingPlugin; 11*a1a3b679SAndreas Boehler 12*a1a3b679SAndreas Boehler/** 13*a1a3b679SAndreas Boehler * Invite-reply POST request parser 14*a1a3b679SAndreas Boehler * 15*a1a3b679SAndreas Boehler * This class parses the invite-reply POST request, as defined in: 16*a1a3b679SAndreas Boehler * 17*a1a3b679SAndreas Boehler * http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-sharing.txt 18*a1a3b679SAndreas Boehler * 19*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/) 20*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 21*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 22*a1a3b679SAndreas Boehler */ 23*a1a3b679SAndreas Boehlerclass InviteReply implements XmlDeserializable { 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler /** 26*a1a3b679SAndreas Boehler * The sharee calendar user address. 27*a1a3b679SAndreas Boehler * 28*a1a3b679SAndreas Boehler * This is the address that the original invite was set to 29*a1a3b679SAndreas Boehler * 30*a1a3b679SAndreas Boehler * @var string 31*a1a3b679SAndreas Boehler */ 32*a1a3b679SAndreas Boehler public $href; 33*a1a3b679SAndreas Boehler 34*a1a3b679SAndreas Boehler /** 35*a1a3b679SAndreas Boehler * The uri to the calendar that was being shared. 36*a1a3b679SAndreas Boehler * 37*a1a3b679SAndreas Boehler * @var string 38*a1a3b679SAndreas Boehler */ 39*a1a3b679SAndreas Boehler public $calendarUri; 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler /** 42*a1a3b679SAndreas Boehler * The id of the invite message that's being responded to 43*a1a3b679SAndreas Boehler * 44*a1a3b679SAndreas Boehler * @var string 45*a1a3b679SAndreas Boehler */ 46*a1a3b679SAndreas Boehler public $inReplyTo; 47*a1a3b679SAndreas Boehler 48*a1a3b679SAndreas Boehler /** 49*a1a3b679SAndreas Boehler * An optional message 50*a1a3b679SAndreas Boehler * 51*a1a3b679SAndreas Boehler * @var string 52*a1a3b679SAndreas Boehler */ 53*a1a3b679SAndreas Boehler public $summary; 54*a1a3b679SAndreas Boehler 55*a1a3b679SAndreas Boehler /** 56*a1a3b679SAndreas Boehler * Either SharingPlugin::STATUS_ACCEPTED or SharingPlugin::STATUS_DECLINED. 57*a1a3b679SAndreas Boehler * 58*a1a3b679SAndreas Boehler * @var int 59*a1a3b679SAndreas Boehler */ 60*a1a3b679SAndreas Boehler public $status; 61*a1a3b679SAndreas Boehler 62*a1a3b679SAndreas Boehler /** 63*a1a3b679SAndreas Boehler * Constructor 64*a1a3b679SAndreas Boehler * 65*a1a3b679SAndreas Boehler * @param string $href 66*a1a3b679SAndreas Boehler * @param string $calendarUri 67*a1a3b679SAndreas Boehler * @param string $inReplyTo 68*a1a3b679SAndreas Boehler * @param string $summary 69*a1a3b679SAndreas Boehler * @param int $status 70*a1a3b679SAndreas Boehler */ 71*a1a3b679SAndreas Boehler function __construct($href, $calendarUri, $inReplyTo, $summary, $status) { 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler $this->href = $href; 74*a1a3b679SAndreas Boehler $this->calendarUri = $calendarUri; 75*a1a3b679SAndreas Boehler $this->inReplyTo = $inReplyTo; 76*a1a3b679SAndreas Boehler $this->summary = $summary; 77*a1a3b679SAndreas Boehler $this->status = $status; 78*a1a3b679SAndreas Boehler 79*a1a3b679SAndreas Boehler } 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler /** 82*a1a3b679SAndreas Boehler * The deserialize method is called during xml parsing. 83*a1a3b679SAndreas Boehler * 84*a1a3b679SAndreas Boehler * This method is called statictly, this is because in theory this method 85*a1a3b679SAndreas Boehler * may be used as a type of constructor, or factory method. 86*a1a3b679SAndreas Boehler * 87*a1a3b679SAndreas Boehler * Often you want to return an instance of the current class, but you are 88*a1a3b679SAndreas Boehler * free to return other data as well. 89*a1a3b679SAndreas Boehler * 90*a1a3b679SAndreas Boehler * You are responsible for advancing the reader to the next element. Not 91*a1a3b679SAndreas Boehler * doing anything will result in a never-ending loop. 92*a1a3b679SAndreas Boehler * 93*a1a3b679SAndreas Boehler * If you just want to skip parsing for this element altogether, you can 94*a1a3b679SAndreas Boehler * just call $reader->next(); 95*a1a3b679SAndreas Boehler * 96*a1a3b679SAndreas Boehler * $reader->parseInnerTree() will parse the entire sub-tree, and advance to 97*a1a3b679SAndreas Boehler * the next element. 98*a1a3b679SAndreas Boehler * 99*a1a3b679SAndreas Boehler * @param Reader $reader 100*a1a3b679SAndreas Boehler * @return mixed 101*a1a3b679SAndreas Boehler */ 102*a1a3b679SAndreas Boehler static function xmlDeserialize(Reader $reader) { 103*a1a3b679SAndreas Boehler 104*a1a3b679SAndreas Boehler $elems = KeyValue::xmlDeserialize($reader); 105*a1a3b679SAndreas Boehler 106*a1a3b679SAndreas Boehler $href = null; 107*a1a3b679SAndreas Boehler $calendarUri = null; 108*a1a3b679SAndreas Boehler $inReplyTo = null; 109*a1a3b679SAndreas Boehler $summary = null; 110*a1a3b679SAndreas Boehler $status = null; 111*a1a3b679SAndreas Boehler 112*a1a3b679SAndreas Boehler foreach ($elems as $name => $value) { 113*a1a3b679SAndreas Boehler 114*a1a3b679SAndreas Boehler switch ($name) { 115*a1a3b679SAndreas Boehler 116*a1a3b679SAndreas Boehler case '{' . Plugin::NS_CALENDARSERVER . '}hosturl' : 117*a1a3b679SAndreas Boehler foreach ($value as $bla) { 118*a1a3b679SAndreas Boehler if ($bla['name'] === '{DAV:}href') { 119*a1a3b679SAndreas Boehler $calendarUri = $bla['value']; 120*a1a3b679SAndreas Boehler } 121*a1a3b679SAndreas Boehler } 122*a1a3b679SAndreas Boehler break; 123*a1a3b679SAndreas Boehler case '{' . Plugin::NS_CALENDARSERVER . '}invite-accepted' : 124*a1a3b679SAndreas Boehler $status = SharingPlugin::STATUS_ACCEPTED; 125*a1a3b679SAndreas Boehler break; 126*a1a3b679SAndreas Boehler case '{' . Plugin::NS_CALENDARSERVER . '}invite-declined' : 127*a1a3b679SAndreas Boehler $status = SharingPlugin::STATUS_DECLINED; 128*a1a3b679SAndreas Boehler break; 129*a1a3b679SAndreas Boehler case '{' . Plugin::NS_CALENDARSERVER . '}in-reply-to' : 130*a1a3b679SAndreas Boehler $inReplyTo = $value; 131*a1a3b679SAndreas Boehler break; 132*a1a3b679SAndreas Boehler case '{' . Plugin::NS_CALENDARSERVER . '}summary' : 133*a1a3b679SAndreas Boehler $summary = $value; 134*a1a3b679SAndreas Boehler break; 135*a1a3b679SAndreas Boehler case '{DAV:}href' : 136*a1a3b679SAndreas Boehler $href = $value; 137*a1a3b679SAndreas Boehler break; 138*a1a3b679SAndreas Boehler } 139*a1a3b679SAndreas Boehler 140*a1a3b679SAndreas Boehler } 141*a1a3b679SAndreas Boehler if (is_null($calendarUri)) { 142*a1a3b679SAndreas Boehler throw new BadRequest('The {http://calendarserver.org/ns/}hosturl/{DAV:}href element must exist'); 143*a1a3b679SAndreas Boehler } 144*a1a3b679SAndreas Boehler 145*a1a3b679SAndreas Boehler return new self($href, $calendarUri, $inReplyTo, $summary, $status); 146*a1a3b679SAndreas Boehler 147*a1a3b679SAndreas Boehler } 148*a1a3b679SAndreas Boehler 149*a1a3b679SAndreas Boehler} 150