1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
<?php
declare(strict_types=1);
namespace Sabre\CalDAV\Xml\Notification;
use Sabre\CalDAV;
use Sabre\CalDAV\SharingPlugin;
use Sabre\DAV;
use Sabre\Xml\Writer;
/**
* This class represents the cs:invite-reply notification element.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class InviteReply implements NotificationInterface
{
/**
* A unique id for the message.
*
* @var string
*/
protected $id;
/**
* Timestamp of the notification.
*
* @var \DateTime
*/
protected $dtStamp;
/**
* The unique id of the notification this was a reply to.
*
* @var string
*/
protected $inReplyTo;
/**
* A url to the recipient of the original (!) notification.
*
* @var string
*/
protected $href;
/**
* The type of message, see the SharingPlugin::STATUS_ constants.
*
* @var int
*/
protected $type;
/**
* A url to the shared calendar.
*
* @var string
*/
protected $hostUrl;
/**
* A description of the share request.
*
* @var string
*/
protected $summary;
/**
* Notification Etag.
*
* @var string
*/
protected $etag;
/**
* Creates the Invite Reply Notification.
*
* This constructor receives an array with the following elements:
*
* * id - A unique id
* * etag - The etag
* * dtStamp - A DateTime object with a timestamp for the notification.
* * inReplyTo - This should refer to the 'id' of the notification
* this is a reply to.
* * type - The type of notification, see SharingPlugin::STATUS_*
* constants for details.
* * hostUrl - A url to the shared calendar.
* * summary - Description of the share, can be the same as the
* calendar, but may also be modified (optional).
*
* @param array $values
*/
public function __construct(array $values)
{
$required = [
'id',
'etag',
'href',
'dtStamp',
'inReplyTo',
'type',
'hostUrl',
];
foreach ($required as $item) {
if (!isset($values[$item])) {
throw new \InvalidArgumentException($item.' is a required constructor option');
}
}
foreach ($values as $key => $value) {
if (!property_exists($this, $key)) {
throw new \InvalidArgumentException('Unknown option: '.$key);
}
$this->$key = $value;
}
}
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
*/
public function xmlSerialize(Writer $writer)
{
$writer->writeElement('{'.CalDAV\Plugin::NS_CALENDARSERVER.'}invite-reply');
}
/**
* This method serializes the entire notification, as it is used in the
* response body.
*
* @param Writer $writer
*/
public function xmlSerializeFull(Writer $writer)
{
$cs = '{'.CalDAV\Plugin::NS_CALENDARSERVER.'}';
$this->dtStamp->setTimezone(new \DateTimeZone('GMT'));
$writer->writeElement($cs.'dtstamp', $this->dtStamp->format('Ymd\\THis\\Z'));
$writer->startElement($cs.'invite-reply');
$writer->writeElement($cs.'uid', $this->id);
$writer->writeElement($cs.'in-reply-to', $this->inReplyTo);
$writer->writeElement('{DAV:}href', $this->href);
switch ($this->type) {
case DAV\Sharing\Plugin::INVITE_ACCEPTED:
$writer->writeElement($cs.'invite-accepted');
break;
case DAV\Sharing\Plugin::INVITE_DECLINED:
$writer->writeElement($cs.'invite-declined');
break;
}
$writer->writeElement($cs.'hosturl', [
'{DAV:}href' => $writer->contextUri.$this->hostUrl,
]);
if ($this->summary) {
$writer->writeElement($cs.'summary', $this->summary);
}
$writer->endElement(); // invite-reply
}
/**
* Returns a unique id for this notification.
*
* This is just the base url. This should generally be some kind of unique
* id.
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Returns the ETag for this notification.
*
* The ETag must be surrounded by literal double-quotes.
*
* @return string
*/
public function getETag()
{
return $this->etag;
}
}
|