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