@@ -3,8 +3,8 @@ |
||
3 | 3 | namespace Sabre\DAV\Sync; |
4 | 4 | |
5 | 5 | use Sabre\DAV; |
6 | -use Sabre\HTTP\RequestInterface; |
|
7 | 6 | use Sabre\DAV\Xml\Request\SyncCollectionReport; |
7 | +use Sabre\HTTP\RequestInterface; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This plugin all WebDAV-sync capabilities to the Server. |
@@ -68,7 +68,7 @@ |
||
68 | 68 | |
69 | 69 | }); |
70 | 70 | |
71 | - $server->on('propFind', [$this, 'propFind']); |
|
71 | + $server->on('propFind', [$this, 'propFind']); |
|
72 | 72 | $server->on('validateTokens', [$this, 'validateTokens']); |
73 | 73 | |
74 | 74 | } |
@@ -20,258 +20,258 @@ |
||
20 | 20 | */ |
21 | 21 | class Plugin extends DAV\ServerPlugin { |
22 | 22 | |
23 | - /** |
|
24 | - * Reference to server object |
|
25 | - * |
|
26 | - * @var DAV\Server |
|
27 | - */ |
|
28 | - protected $server; |
|
29 | - |
|
30 | - const SYNCTOKEN_PREFIX = 'http://sabre.io/ns/sync/'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Returns a plugin name. |
|
34 | - * |
|
35 | - * Using this name other plugins will be able to access other plugins |
|
36 | - * using \Sabre\DAV\Server::getPlugin |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getPluginName() { |
|
41 | - |
|
42 | - return 'sync'; |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Initializes the plugin. |
|
48 | - * |
|
49 | - * This is when the plugin registers it's hooks. |
|
50 | - * |
|
51 | - * @param DAV\Server $server |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function initialize(DAV\Server $server) { |
|
55 | - |
|
56 | - $this->server = $server; |
|
57 | - $server->xml->elementMap['{DAV:}sync-collection'] = 'Sabre\\DAV\\Xml\\Request\\SyncCollectionReport'; |
|
58 | - |
|
59 | - $self = $this; |
|
60 | - |
|
61 | - $server->on('report', function($reportName, $dom, $uri) use ($self) { |
|
62 | - |
|
63 | - if ($reportName === '{DAV:}sync-collection') { |
|
64 | - $this->server->transactionType = 'report-sync-collection'; |
|
65 | - $self->syncCollection($uri, $dom); |
|
66 | - return false; |
|
67 | - } |
|
68 | - |
|
69 | - }); |
|
70 | - |
|
71 | - $server->on('propFind', [$this, 'propFind']); |
|
72 | - $server->on('validateTokens', [$this, 'validateTokens']); |
|
73 | - |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns a list of reports this plugin supports. |
|
78 | - * |
|
79 | - * This will be used in the {DAV:}supported-report-set property. |
|
80 | - * Note that you still need to subscribe to the 'report' event to actually |
|
81 | - * implement them |
|
82 | - * |
|
83 | - * @param string $uri |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function getSupportedReportSet($uri) { |
|
87 | - |
|
88 | - $node = $this->server->tree->getNodeForPath($uri); |
|
89 | - if ($node instanceof ISyncCollection && $node->getSyncToken()) { |
|
90 | - return [ |
|
91 | - '{DAV:}sync-collection', |
|
92 | - ]; |
|
93 | - } |
|
94 | - |
|
95 | - return []; |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * This method handles the {DAV:}sync-collection HTTP REPORT. |
|
102 | - * |
|
103 | - * @param string $uri |
|
104 | - * @param SyncCollectionReport $report |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function syncCollection($uri, SyncCollectionReport $report) { |
|
108 | - |
|
109 | - // Getting the data |
|
110 | - $node = $this->server->tree->getNodeForPath($uri); |
|
111 | - if (!$node instanceof ISyncCollection) { |
|
112 | - throw new DAV\Exception\ReportNotSupported('The {DAV:}sync-collection REPORT is not supported on this url.'); |
|
113 | - } |
|
114 | - $token = $node->getSyncToken(); |
|
115 | - if (!$token) { |
|
116 | - throw new DAV\Exception\ReportNotSupported('No sync information is available at this node'); |
|
117 | - } |
|
118 | - |
|
119 | - $syncToken = $report->syncToken; |
|
120 | - if (!is_null($syncToken)) { |
|
121 | - // Sync-token must start with our prefix |
|
122 | - if (substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) { |
|
123 | - throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token'); |
|
124 | - } |
|
125 | - |
|
126 | - $syncToken = substr($syncToken, strlen(self::SYNCTOKEN_PREFIX)); |
|
127 | - |
|
128 | - } |
|
129 | - $changeInfo = $node->getChanges($syncToken, $report->syncLevel, $report->limit); |
|
130 | - |
|
131 | - if (is_null($changeInfo)) { |
|
132 | - |
|
133 | - throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token'); |
|
134 | - |
|
135 | - } |
|
136 | - |
|
137 | - // Encoding the response |
|
138 | - $this->sendSyncCollectionResponse( |
|
139 | - $changeInfo['syncToken'], |
|
140 | - $uri, |
|
141 | - $changeInfo['added'], |
|
142 | - $changeInfo['modified'], |
|
143 | - $changeInfo['deleted'], |
|
144 | - $report->properties |
|
145 | - ); |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Sends the response to a sync-collection request. |
|
151 | - * |
|
152 | - * @param string $syncToken |
|
153 | - * @param string $collectionUrl |
|
154 | - * @param array $added |
|
155 | - * @param array $modified |
|
156 | - * @param array $deleted |
|
157 | - * @param array $properties |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties) { |
|
161 | - |
|
162 | - |
|
163 | - $fullPaths = []; |
|
164 | - |
|
165 | - // Pre-fetching children, if this is possible. |
|
166 | - foreach (array_merge($added, $modified) as $item) { |
|
167 | - $fullPath = $collectionUrl . '/' . $item; |
|
168 | - $fullPaths[] = $fullPath; |
|
169 | - } |
|
170 | - |
|
171 | - $responses = []; |
|
172 | - foreach ($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) { |
|
173 | - |
|
174 | - // The 'Property_Response' class is responsible for generating a |
|
175 | - // single {DAV:}response xml element. |
|
176 | - $responses[] = new DAV\Xml\Element\Response($fullPath, $props); |
|
177 | - |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - // Deleted items also show up as 'responses'. They have no properties, |
|
183 | - // and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'. |
|
184 | - foreach ($deleted as $item) { |
|
185 | - |
|
186 | - $fullPath = $collectionUrl . '/' . $item; |
|
187 | - $responses[] = new DAV\Xml\Element\Response($fullPath, [], 404); |
|
188 | - |
|
189 | - } |
|
190 | - $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX . $syncToken); |
|
191 | - |
|
192 | - $this->server->httpResponse->setStatus(207); |
|
193 | - $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
194 | - $this->server->httpResponse->setBody( |
|
195 | - $this->server->xml->write('{DAV:}multistatus', $multiStatus, $this->server->getBaseUri()) |
|
196 | - ); |
|
197 | - |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * This method is triggered whenever properties are requested for a node. |
|
202 | - * We intercept this to see if we must return a {DAV:}sync-token. |
|
203 | - * |
|
204 | - * @param DAV\PropFind $propFind |
|
205 | - * @param DAV\INode $node |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - public function propFind(DAV\PropFind $propFind, DAV\INode $node) { |
|
209 | - |
|
210 | - $propFind->handle('{DAV:}sync-token', function() use ($node) { |
|
211 | - if (!$node instanceof ISyncCollection || !$token = $node->getSyncToken()) { |
|
212 | - return; |
|
213 | - } |
|
214 | - return self::SYNCTOKEN_PREFIX . $token; |
|
215 | - }); |
|
216 | - |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * The validateTokens event is triggered before every request. |
|
221 | - * |
|
222 | - * It's a moment where this plugin can check all the supplied lock tokens |
|
223 | - * in the If: header, and check if they are valid. |
|
224 | - * |
|
225 | - * @param RequestInterface $request |
|
226 | - * @param array $conditions |
|
227 | - * @return void |
|
228 | - */ |
|
229 | - public function validateTokens(RequestInterface $request, &$conditions) { |
|
230 | - |
|
231 | - foreach ($conditions as $kk => $condition) { |
|
232 | - |
|
233 | - foreach ($condition['tokens'] as $ii => $token) { |
|
234 | - |
|
235 | - // Sync-tokens must always start with our designated prefix. |
|
236 | - if (substr($token['token'], 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) { |
|
237 | - continue; |
|
238 | - } |
|
239 | - |
|
240 | - // Checking if the token is a match. |
|
241 | - $node = $this->server->tree->getNodeForPath($condition['uri']); |
|
242 | - |
|
243 | - if ( |
|
244 | - $node instanceof ISyncCollection && |
|
245 | - $node->getSyncToken() == substr($token['token'], strlen(self::SYNCTOKEN_PREFIX)) |
|
246 | - ) { |
|
247 | - $conditions[$kk]['tokens'][$ii]['validToken'] = true; |
|
248 | - } |
|
249 | - |
|
250 | - } |
|
251 | - |
|
252 | - } |
|
253 | - |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Returns a bunch of meta-data about the plugin. |
|
258 | - * |
|
259 | - * Providing this information is optional, and is mainly displayed by the |
|
260 | - * Browser plugin. |
|
261 | - * |
|
262 | - * The description key in the returned array may contain html and will not |
|
263 | - * be sanitized. |
|
264 | - * |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - public function getPluginInfo() { |
|
268 | - |
|
269 | - return [ |
|
270 | - 'name' => $this->getPluginName(), |
|
271 | - 'description' => 'Adds support for WebDAV Collection Sync (rfc6578)', |
|
272 | - 'link' => 'http://sabre.io/dav/sync/', |
|
273 | - ]; |
|
274 | - |
|
275 | - } |
|
23 | + /** |
|
24 | + * Reference to server object |
|
25 | + * |
|
26 | + * @var DAV\Server |
|
27 | + */ |
|
28 | + protected $server; |
|
29 | + |
|
30 | + const SYNCTOKEN_PREFIX = 'http://sabre.io/ns/sync/'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Returns a plugin name. |
|
34 | + * |
|
35 | + * Using this name other plugins will be able to access other plugins |
|
36 | + * using \Sabre\DAV\Server::getPlugin |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getPluginName() { |
|
41 | + |
|
42 | + return 'sync'; |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Initializes the plugin. |
|
48 | + * |
|
49 | + * This is when the plugin registers it's hooks. |
|
50 | + * |
|
51 | + * @param DAV\Server $server |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function initialize(DAV\Server $server) { |
|
55 | + |
|
56 | + $this->server = $server; |
|
57 | + $server->xml->elementMap['{DAV:}sync-collection'] = 'Sabre\\DAV\\Xml\\Request\\SyncCollectionReport'; |
|
58 | + |
|
59 | + $self = $this; |
|
60 | + |
|
61 | + $server->on('report', function($reportName, $dom, $uri) use ($self) { |
|
62 | + |
|
63 | + if ($reportName === '{DAV:}sync-collection') { |
|
64 | + $this->server->transactionType = 'report-sync-collection'; |
|
65 | + $self->syncCollection($uri, $dom); |
|
66 | + return false; |
|
67 | + } |
|
68 | + |
|
69 | + }); |
|
70 | + |
|
71 | + $server->on('propFind', [$this, 'propFind']); |
|
72 | + $server->on('validateTokens', [$this, 'validateTokens']); |
|
73 | + |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns a list of reports this plugin supports. |
|
78 | + * |
|
79 | + * This will be used in the {DAV:}supported-report-set property. |
|
80 | + * Note that you still need to subscribe to the 'report' event to actually |
|
81 | + * implement them |
|
82 | + * |
|
83 | + * @param string $uri |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function getSupportedReportSet($uri) { |
|
87 | + |
|
88 | + $node = $this->server->tree->getNodeForPath($uri); |
|
89 | + if ($node instanceof ISyncCollection && $node->getSyncToken()) { |
|
90 | + return [ |
|
91 | + '{DAV:}sync-collection', |
|
92 | + ]; |
|
93 | + } |
|
94 | + |
|
95 | + return []; |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * This method handles the {DAV:}sync-collection HTTP REPORT. |
|
102 | + * |
|
103 | + * @param string $uri |
|
104 | + * @param SyncCollectionReport $report |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function syncCollection($uri, SyncCollectionReport $report) { |
|
108 | + |
|
109 | + // Getting the data |
|
110 | + $node = $this->server->tree->getNodeForPath($uri); |
|
111 | + if (!$node instanceof ISyncCollection) { |
|
112 | + throw new DAV\Exception\ReportNotSupported('The {DAV:}sync-collection REPORT is not supported on this url.'); |
|
113 | + } |
|
114 | + $token = $node->getSyncToken(); |
|
115 | + if (!$token) { |
|
116 | + throw new DAV\Exception\ReportNotSupported('No sync information is available at this node'); |
|
117 | + } |
|
118 | + |
|
119 | + $syncToken = $report->syncToken; |
|
120 | + if (!is_null($syncToken)) { |
|
121 | + // Sync-token must start with our prefix |
|
122 | + if (substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) { |
|
123 | + throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token'); |
|
124 | + } |
|
125 | + |
|
126 | + $syncToken = substr($syncToken, strlen(self::SYNCTOKEN_PREFIX)); |
|
127 | + |
|
128 | + } |
|
129 | + $changeInfo = $node->getChanges($syncToken, $report->syncLevel, $report->limit); |
|
130 | + |
|
131 | + if (is_null($changeInfo)) { |
|
132 | + |
|
133 | + throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token'); |
|
134 | + |
|
135 | + } |
|
136 | + |
|
137 | + // Encoding the response |
|
138 | + $this->sendSyncCollectionResponse( |
|
139 | + $changeInfo['syncToken'], |
|
140 | + $uri, |
|
141 | + $changeInfo['added'], |
|
142 | + $changeInfo['modified'], |
|
143 | + $changeInfo['deleted'], |
|
144 | + $report->properties |
|
145 | + ); |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Sends the response to a sync-collection request. |
|
151 | + * |
|
152 | + * @param string $syncToken |
|
153 | + * @param string $collectionUrl |
|
154 | + * @param array $added |
|
155 | + * @param array $modified |
|
156 | + * @param array $deleted |
|
157 | + * @param array $properties |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties) { |
|
161 | + |
|
162 | + |
|
163 | + $fullPaths = []; |
|
164 | + |
|
165 | + // Pre-fetching children, if this is possible. |
|
166 | + foreach (array_merge($added, $modified) as $item) { |
|
167 | + $fullPath = $collectionUrl . '/' . $item; |
|
168 | + $fullPaths[] = $fullPath; |
|
169 | + } |
|
170 | + |
|
171 | + $responses = []; |
|
172 | + foreach ($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) { |
|
173 | + |
|
174 | + // The 'Property_Response' class is responsible for generating a |
|
175 | + // single {DAV:}response xml element. |
|
176 | + $responses[] = new DAV\Xml\Element\Response($fullPath, $props); |
|
177 | + |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + // Deleted items also show up as 'responses'. They have no properties, |
|
183 | + // and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'. |
|
184 | + foreach ($deleted as $item) { |
|
185 | + |
|
186 | + $fullPath = $collectionUrl . '/' . $item; |
|
187 | + $responses[] = new DAV\Xml\Element\Response($fullPath, [], 404); |
|
188 | + |
|
189 | + } |
|
190 | + $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX . $syncToken); |
|
191 | + |
|
192 | + $this->server->httpResponse->setStatus(207); |
|
193 | + $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
194 | + $this->server->httpResponse->setBody( |
|
195 | + $this->server->xml->write('{DAV:}multistatus', $multiStatus, $this->server->getBaseUri()) |
|
196 | + ); |
|
197 | + |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * This method is triggered whenever properties are requested for a node. |
|
202 | + * We intercept this to see if we must return a {DAV:}sync-token. |
|
203 | + * |
|
204 | + * @param DAV\PropFind $propFind |
|
205 | + * @param DAV\INode $node |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + public function propFind(DAV\PropFind $propFind, DAV\INode $node) { |
|
209 | + |
|
210 | + $propFind->handle('{DAV:}sync-token', function() use ($node) { |
|
211 | + if (!$node instanceof ISyncCollection || !$token = $node->getSyncToken()) { |
|
212 | + return; |
|
213 | + } |
|
214 | + return self::SYNCTOKEN_PREFIX . $token; |
|
215 | + }); |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * The validateTokens event is triggered before every request. |
|
221 | + * |
|
222 | + * It's a moment where this plugin can check all the supplied lock tokens |
|
223 | + * in the If: header, and check if they are valid. |
|
224 | + * |
|
225 | + * @param RequestInterface $request |
|
226 | + * @param array $conditions |
|
227 | + * @return void |
|
228 | + */ |
|
229 | + public function validateTokens(RequestInterface $request, &$conditions) { |
|
230 | + |
|
231 | + foreach ($conditions as $kk => $condition) { |
|
232 | + |
|
233 | + foreach ($condition['tokens'] as $ii => $token) { |
|
234 | + |
|
235 | + // Sync-tokens must always start with our designated prefix. |
|
236 | + if (substr($token['token'], 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) { |
|
237 | + continue; |
|
238 | + } |
|
239 | + |
|
240 | + // Checking if the token is a match. |
|
241 | + $node = $this->server->tree->getNodeForPath($condition['uri']); |
|
242 | + |
|
243 | + if ( |
|
244 | + $node instanceof ISyncCollection && |
|
245 | + $node->getSyncToken() == substr($token['token'], strlen(self::SYNCTOKEN_PREFIX)) |
|
246 | + ) { |
|
247 | + $conditions[$kk]['tokens'][$ii]['validToken'] = true; |
|
248 | + } |
|
249 | + |
|
250 | + } |
|
251 | + |
|
252 | + } |
|
253 | + |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Returns a bunch of meta-data about the plugin. |
|
258 | + * |
|
259 | + * Providing this information is optional, and is mainly displayed by the |
|
260 | + * Browser plugin. |
|
261 | + * |
|
262 | + * The description key in the returned array may contain html and will not |
|
263 | + * be sanitized. |
|
264 | + * |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + public function getPluginInfo() { |
|
268 | + |
|
269 | + return [ |
|
270 | + 'name' => $this->getPluginName(), |
|
271 | + 'description' => 'Adds support for WebDAV Collection Sync (rfc6578)', |
|
272 | + 'link' => 'http://sabre.io/dav/sync/', |
|
273 | + ]; |
|
274 | + |
|
275 | + } |
|
276 | 276 | |
277 | 277 | } |
@@ -3,8 +3,8 @@ |
||
3 | 3 | namespace Sabre\DAV\Xml\Element; |
4 | 4 | |
5 | 5 | use Sabre\DAV\Xml\Property\Complex; |
6 | -use Sabre\Xml\XmlDeserializable; |
|
7 | 6 | use Sabre\Xml\Reader; |
7 | +use Sabre\Xml\XmlDeserializable; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class is responsible for decoding the {DAV:}prop element as it appears |
@@ -19,98 +19,98 @@ |
||
19 | 19 | */ |
20 | 20 | class Prop implements XmlDeserializable { |
21 | 21 | |
22 | - /** |
|
23 | - * The deserialize method is called during xml parsing. |
|
24 | - * |
|
25 | - * This method is called statictly, this is because in theory this method |
|
26 | - * may be used as a type of constructor, or factory method. |
|
27 | - * |
|
28 | - * Often you want to return an instance of the current class, but you are |
|
29 | - * free to return other data as well. |
|
30 | - * |
|
31 | - * You are responsible for advancing the reader to the next element. Not |
|
32 | - * doing anything will result in a never-ending loop. |
|
33 | - * |
|
34 | - * If you just want to skip parsing for this element altogether, you can |
|
35 | - * just call $reader->next(); |
|
36 | - * |
|
37 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
38 | - * the next element. |
|
39 | - * |
|
40 | - * @param Reader $reader |
|
41 | - * @return mixed |
|
42 | - */ |
|
43 | - static function xmlDeserialize(Reader $reader) { |
|
44 | - |
|
45 | - // If there's no children, we don't do anything. |
|
46 | - if ($reader->isEmptyElement) { |
|
47 | - $reader->next(); |
|
48 | - return []; |
|
49 | - } |
|
50 | - |
|
51 | - $values = []; |
|
52 | - |
|
53 | - $reader->read(); |
|
54 | - do { |
|
55 | - |
|
56 | - if ($reader->nodeType === Reader::ELEMENT) { |
|
57 | - |
|
58 | - $clark = $reader->getClark(); |
|
59 | - $values[$clark] = self::parseCurrentElement($reader)['value']; |
|
60 | - |
|
61 | - } else { |
|
62 | - $reader->read(); |
|
63 | - } |
|
64 | - |
|
65 | - } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
66 | - |
|
67 | - $reader->read(); |
|
68 | - |
|
69 | - return $values; |
|
70 | - |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * This function behaves similar to Sabre\Xml\Reader::parseCurrentElement, |
|
75 | - * but instead of creating deep xml array structures, it will turn any |
|
76 | - * top-level element it doesn't recognize into either a string, or an |
|
77 | - * XmlFragment class. |
|
78 | - * |
|
79 | - * This method returns arn array with 2 properties: |
|
80 | - * * name - A clark-notation XML element name. |
|
81 | - * * value - The parsed value. |
|
82 | - * |
|
83 | - * @param Reader $reader |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - private static function parseCurrentElement(Reader $reader) { |
|
87 | - |
|
88 | - $name = $reader->getClark(); |
|
89 | - |
|
90 | - if (array_key_exists($name, $reader->elementMap)) { |
|
91 | - $deserializer = $reader->elementMap[$name]; |
|
92 | - if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
|
93 | - $value = call_user_func([ $deserializer, 'xmlDeserialize' ], $reader); |
|
94 | - } elseif (is_callable($deserializer)) { |
|
95 | - $value = call_user_func($deserializer, $reader); |
|
96 | - } else { |
|
97 | - $type = gettype($deserializer); |
|
98 | - if ($type === 'string') { |
|
99 | - $type .= ' (' . $deserializer . ')'; |
|
100 | - } elseif ($type === 'object') { |
|
101 | - $type .= ' (' . get_class($deserializer) . ')'; |
|
102 | - } |
|
103 | - throw new \LogicException('Could not use this type as a deserializer: ' . $type); |
|
104 | - } |
|
105 | - } else { |
|
106 | - $value = Complex::xmlDeserialize($reader); |
|
107 | - } |
|
108 | - |
|
109 | - return [ |
|
110 | - 'name' => $name, |
|
111 | - 'value' => $value, |
|
112 | - ]; |
|
113 | - |
|
114 | - } |
|
22 | + /** |
|
23 | + * The deserialize method is called during xml parsing. |
|
24 | + * |
|
25 | + * This method is called statictly, this is because in theory this method |
|
26 | + * may be used as a type of constructor, or factory method. |
|
27 | + * |
|
28 | + * Often you want to return an instance of the current class, but you are |
|
29 | + * free to return other data as well. |
|
30 | + * |
|
31 | + * You are responsible for advancing the reader to the next element. Not |
|
32 | + * doing anything will result in a never-ending loop. |
|
33 | + * |
|
34 | + * If you just want to skip parsing for this element altogether, you can |
|
35 | + * just call $reader->next(); |
|
36 | + * |
|
37 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
38 | + * the next element. |
|
39 | + * |
|
40 | + * @param Reader $reader |
|
41 | + * @return mixed |
|
42 | + */ |
|
43 | + static function xmlDeserialize(Reader $reader) { |
|
44 | + |
|
45 | + // If there's no children, we don't do anything. |
|
46 | + if ($reader->isEmptyElement) { |
|
47 | + $reader->next(); |
|
48 | + return []; |
|
49 | + } |
|
50 | + |
|
51 | + $values = []; |
|
52 | + |
|
53 | + $reader->read(); |
|
54 | + do { |
|
55 | + |
|
56 | + if ($reader->nodeType === Reader::ELEMENT) { |
|
57 | + |
|
58 | + $clark = $reader->getClark(); |
|
59 | + $values[$clark] = self::parseCurrentElement($reader)['value']; |
|
60 | + |
|
61 | + } else { |
|
62 | + $reader->read(); |
|
63 | + } |
|
64 | + |
|
65 | + } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
66 | + |
|
67 | + $reader->read(); |
|
68 | + |
|
69 | + return $values; |
|
70 | + |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * This function behaves similar to Sabre\Xml\Reader::parseCurrentElement, |
|
75 | + * but instead of creating deep xml array structures, it will turn any |
|
76 | + * top-level element it doesn't recognize into either a string, or an |
|
77 | + * XmlFragment class. |
|
78 | + * |
|
79 | + * This method returns arn array with 2 properties: |
|
80 | + * * name - A clark-notation XML element name. |
|
81 | + * * value - The parsed value. |
|
82 | + * |
|
83 | + * @param Reader $reader |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + private static function parseCurrentElement(Reader $reader) { |
|
87 | + |
|
88 | + $name = $reader->getClark(); |
|
89 | + |
|
90 | + if (array_key_exists($name, $reader->elementMap)) { |
|
91 | + $deserializer = $reader->elementMap[$name]; |
|
92 | + if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
|
93 | + $value = call_user_func([ $deserializer, 'xmlDeserialize' ], $reader); |
|
94 | + } elseif (is_callable($deserializer)) { |
|
95 | + $value = call_user_func($deserializer, $reader); |
|
96 | + } else { |
|
97 | + $type = gettype($deserializer); |
|
98 | + if ($type === 'string') { |
|
99 | + $type .= ' (' . $deserializer . ')'; |
|
100 | + } elseif ($type === 'object') { |
|
101 | + $type .= ' (' . get_class($deserializer) . ')'; |
|
102 | + } |
|
103 | + throw new \LogicException('Could not use this type as a deserializer: ' . $type); |
|
104 | + } |
|
105 | + } else { |
|
106 | + $value = Complex::xmlDeserialize($reader); |
|
107 | + } |
|
108 | + |
|
109 | + return [ |
|
110 | + 'name' => $name, |
|
111 | + 'value' => $value, |
|
112 | + ]; |
|
113 | + |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | if (array_key_exists($name, $reader->elementMap)) { |
91 | 91 | $deserializer = $reader->elementMap[$name]; |
92 | 92 | if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
93 | - $value = call_user_func([ $deserializer, 'xmlDeserialize' ], $reader); |
|
93 | + $value = call_user_func([$deserializer, 'xmlDeserialize'], $reader); |
|
94 | 94 | } elseif (is_callable($deserializer)) { |
95 | 95 | $value = call_user_func($deserializer, $reader); |
96 | 96 | } else { |
@@ -176,7 +176,7 @@ |
||
176 | 176 | * the next element. |
177 | 177 | * |
178 | 178 | * @param Reader $reader |
179 | - * @return mixed |
|
179 | + * @return Response |
|
180 | 180 | */ |
181 | 181 | static function xmlDeserialize(Reader $reader) { |
182 | 182 |
@@ -234,12 +234,12 @@ |
||
234 | 234 | break; |
235 | 235 | case '{DAV:}propstat' : |
236 | 236 | $status = $elem['value']['{DAV:}status']; |
237 | - list(, $status, ) = explode(' ', $status, 3); |
|
237 | + list(, $status,) = explode(' ', $status, 3); |
|
238 | 238 | $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
239 | 239 | if ($properties) $propertyLists[$status] = $properties; |
240 | 240 | break; |
241 | 241 | case '{DAV:}status' : |
242 | - list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
|
242 | + list(, $statusCode,) = explode(' ', $elem['value'], 3); |
|
243 | 243 | break; |
244 | 244 | |
245 | 245 | } |
@@ -236,7 +236,9 @@ |
||
236 | 236 | $status = $elem['value']['{DAV:}status']; |
237 | 237 | list(, $status, ) = explode(' ', $status, 3); |
238 | 238 | $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
239 | - if ($properties) $propertyLists[$status] = $properties; |
|
239 | + if ($properties) { |
|
240 | + $propertyLists[$status] = $properties; |
|
241 | + } |
|
240 | 242 | break; |
241 | 243 | case '{DAV:}status' : |
242 | 244 | list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
@@ -19,128 +19,128 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class Response implements Element { |
21 | 21 | |
22 | - /** |
|
23 | - * Url for the response |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $href; |
|
28 | - |
|
29 | - /** |
|
30 | - * Propertylist, ordered by HTTP status code |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $responseProperties; |
|
35 | - |
|
36 | - /** |
|
37 | - * The HTTP status for an entire response. |
|
38 | - * |
|
39 | - * This is currently only used in WebDAV-Sync |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $httpStatus; |
|
44 | - |
|
45 | - /** |
|
46 | - * The href argument is a url relative to the root of the server. This |
|
47 | - * class will calculate the full path. |
|
48 | - * |
|
49 | - * The responseProperties argument is a list of properties |
|
50 | - * within an array with keys representing HTTP status codes |
|
51 | - * |
|
52 | - * Besides specific properties, the entire {DAV:}response element may also |
|
53 | - * have a http status code. |
|
54 | - * In most cases you don't need it. |
|
55 | - * |
|
56 | - * This is currently used by the Sync extension to indicate that a node is |
|
57 | - * deleted. |
|
58 | - * |
|
59 | - * @param string $href |
|
60 | - * @param array $responseProperties |
|
61 | - * @param string $httpStatus |
|
62 | - */ |
|
63 | - public function __construct($href, array $responseProperties, $httpStatus = null) { |
|
64 | - |
|
65 | - $this->href = $href; |
|
66 | - $this->responseProperties = $responseProperties; |
|
67 | - $this->httpStatus = $httpStatus; |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns the url |
|
73 | - * |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function getHref() { |
|
77 | - |
|
78 | - return $this->href; |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns the httpStatus value |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function getHttpStatus() { |
|
88 | - |
|
89 | - return $this->httpStatus; |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Returns the property list |
|
95 | - * |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public function getResponseProperties() { |
|
99 | - |
|
100 | - return $this->responseProperties; |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * The serialize method is called during xml writing. |
|
107 | - * |
|
108 | - * It should use the $writer argument to encode this object into XML. |
|
109 | - * |
|
110 | - * Important note: it is not needed to create the parent element. The |
|
111 | - * parent element is already created, and we only have to worry about |
|
112 | - * attributes, child elements and text (if any). |
|
113 | - * |
|
114 | - * Important note 2: If you are writing any new elements, you are also |
|
115 | - * responsible for closing them. |
|
116 | - * |
|
117 | - * @param Writer $writer |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function xmlSerialize(Writer $writer) { |
|
121 | - |
|
122 | - if ($status = $this->getHTTPStatus()) { |
|
123 | - $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
124 | - } |
|
125 | - $writer->writeElement('{DAV:}href', $writer->contextUri . \Sabre\HTTP\encodePath($this->getHref())); |
|
126 | - |
|
127 | - $empty = true; |
|
128 | - |
|
129 | - foreach ($this->getResponseProperties() as $status => $properties) { |
|
130 | - |
|
131 | - // Skipping empty lists |
|
132 | - if (!$properties || (!ctype_digit($status) && !is_int($status))) { |
|
133 | - continue; |
|
134 | - } |
|
135 | - $empty = false; |
|
136 | - $writer->startElement('{DAV:}propstat'); |
|
137 | - $writer->writeElement('{DAV:}prop', $properties); |
|
138 | - $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
139 | - $writer->endElement(); // {DAV:}propstat |
|
140 | - |
|
141 | - } |
|
142 | - if ($empty) { |
|
143 | - /* |
|
22 | + /** |
|
23 | + * Url for the response |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $href; |
|
28 | + |
|
29 | + /** |
|
30 | + * Propertylist, ordered by HTTP status code |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $responseProperties; |
|
35 | + |
|
36 | + /** |
|
37 | + * The HTTP status for an entire response. |
|
38 | + * |
|
39 | + * This is currently only used in WebDAV-Sync |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $httpStatus; |
|
44 | + |
|
45 | + /** |
|
46 | + * The href argument is a url relative to the root of the server. This |
|
47 | + * class will calculate the full path. |
|
48 | + * |
|
49 | + * The responseProperties argument is a list of properties |
|
50 | + * within an array with keys representing HTTP status codes |
|
51 | + * |
|
52 | + * Besides specific properties, the entire {DAV:}response element may also |
|
53 | + * have a http status code. |
|
54 | + * In most cases you don't need it. |
|
55 | + * |
|
56 | + * This is currently used by the Sync extension to indicate that a node is |
|
57 | + * deleted. |
|
58 | + * |
|
59 | + * @param string $href |
|
60 | + * @param array $responseProperties |
|
61 | + * @param string $httpStatus |
|
62 | + */ |
|
63 | + public function __construct($href, array $responseProperties, $httpStatus = null) { |
|
64 | + |
|
65 | + $this->href = $href; |
|
66 | + $this->responseProperties = $responseProperties; |
|
67 | + $this->httpStatus = $httpStatus; |
|
68 | + |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns the url |
|
73 | + * |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function getHref() { |
|
77 | + |
|
78 | + return $this->href; |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns the httpStatus value |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function getHttpStatus() { |
|
88 | + |
|
89 | + return $this->httpStatus; |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Returns the property list |
|
95 | + * |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public function getResponseProperties() { |
|
99 | + |
|
100 | + return $this->responseProperties; |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * The serialize method is called during xml writing. |
|
107 | + * |
|
108 | + * It should use the $writer argument to encode this object into XML. |
|
109 | + * |
|
110 | + * Important note: it is not needed to create the parent element. The |
|
111 | + * parent element is already created, and we only have to worry about |
|
112 | + * attributes, child elements and text (if any). |
|
113 | + * |
|
114 | + * Important note 2: If you are writing any new elements, you are also |
|
115 | + * responsible for closing them. |
|
116 | + * |
|
117 | + * @param Writer $writer |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function xmlSerialize(Writer $writer) { |
|
121 | + |
|
122 | + if ($status = $this->getHTTPStatus()) { |
|
123 | + $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
124 | + } |
|
125 | + $writer->writeElement('{DAV:}href', $writer->contextUri . \Sabre\HTTP\encodePath($this->getHref())); |
|
126 | + |
|
127 | + $empty = true; |
|
128 | + |
|
129 | + foreach ($this->getResponseProperties() as $status => $properties) { |
|
130 | + |
|
131 | + // Skipping empty lists |
|
132 | + if (!$properties || (!ctype_digit($status) && !is_int($status))) { |
|
133 | + continue; |
|
134 | + } |
|
135 | + $empty = false; |
|
136 | + $writer->startElement('{DAV:}propstat'); |
|
137 | + $writer->writeElement('{DAV:}prop', $properties); |
|
138 | + $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
139 | + $writer->endElement(); // {DAV:}propstat |
|
140 | + |
|
141 | + } |
|
142 | + if ($empty) { |
|
143 | + /* |
|
144 | 144 | * The WebDAV spec _requires_ at least one DAV:propstat to appear for |
145 | 145 | * every DAV:response. In some circumstances however, there are no |
146 | 146 | * properties to encode. |
@@ -148,106 +148,106 @@ discard block |
||
148 | 148 | * In those cases we MUST specify at least one DAV:propstat anyway, with |
149 | 149 | * no properties. |
150 | 150 | */ |
151 | - $writer->writeElement('{DAV:}propstat', [ |
|
152 | - '{DAV:}prop' => [], |
|
153 | - '{DAV:}status' => 'HTTP/1.1 418 ' . \Sabre\HTTP\Response::$statusCodes[418] |
|
154 | - ]); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * The deserialize method is called during xml parsing. |
|
162 | - * |
|
163 | - * This method is called statictly, this is because in theory this method |
|
164 | - * may be used as a type of constructor, or factory method. |
|
165 | - * |
|
166 | - * Often you want to return an instance of the current class, but you are |
|
167 | - * free to return other data as well. |
|
168 | - * |
|
169 | - * You are responsible for advancing the reader to the next element. Not |
|
170 | - * doing anything will result in a never-ending loop. |
|
171 | - * |
|
172 | - * If you just want to skip parsing for this element altogether, you can |
|
173 | - * just call $reader->next(); |
|
174 | - * |
|
175 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
176 | - * the next element. |
|
177 | - * |
|
178 | - * @param Reader $reader |
|
179 | - * @return mixed |
|
180 | - */ |
|
181 | - static function xmlDeserialize(Reader $reader) { |
|
182 | - |
|
183 | - $reader->pushContext(); |
|
184 | - |
|
185 | - $reader->elementMap['{DAV:}propstat'] = 'Sabre\\Xml\\Element\\KeyValue'; |
|
186 | - |
|
187 | - // We are overriding the parser for {DAV:}prop. This deserializer is |
|
188 | - // almost identical to the one for Sabre\Xml\Element\KeyValue. |
|
189 | - // |
|
190 | - // The difference is that if there are any child-elements inside of |
|
191 | - // {DAV:}prop, that have no value, normally any deserializers are |
|
192 | - // called. But we don't want this, because a singular element without |
|
193 | - // child-elements implies 'no value' in {DAV:}prop, so we want to skip |
|
194 | - // deserializers and just set null for those. |
|
195 | - $reader->elementMap['{DAV:}prop'] = function(Reader $reader) { |
|
196 | - |
|
197 | - if ($reader->isEmptyElement) { |
|
198 | - $reader->next(); |
|
199 | - return []; |
|
200 | - } |
|
201 | - $values = []; |
|
202 | - $reader->read(); |
|
203 | - do { |
|
204 | - if ($reader->nodeType === Reader::ELEMENT) { |
|
205 | - $clark = $reader->getClark(); |
|
206 | - |
|
207 | - if ($reader->isEmptyElement) { |
|
208 | - $values[$clark] = null; |
|
209 | - $reader->next(); |
|
210 | - } else { |
|
211 | - $values[$clark] = $reader->parseCurrentElement()['value']; |
|
212 | - } |
|
213 | - } else { |
|
214 | - $reader->read(); |
|
215 | - } |
|
216 | - } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
217 | - $reader->read(); |
|
218 | - return $values; |
|
219 | - |
|
220 | - }; |
|
221 | - $elems = $reader->parseInnerTree(); |
|
222 | - $reader->popContext(); |
|
223 | - |
|
224 | - $href = null; |
|
225 | - $propertyLists = []; |
|
226 | - $statusCode = null; |
|
227 | - |
|
228 | - foreach ($elems as $elem) { |
|
229 | - |
|
230 | - switch ($elem['name']) { |
|
231 | - |
|
232 | - case '{DAV:}href' : |
|
233 | - $href = $elem['value']; |
|
234 | - break; |
|
235 | - case '{DAV:}propstat' : |
|
236 | - $status = $elem['value']['{DAV:}status']; |
|
237 | - list(, $status, ) = explode(' ', $status, 3); |
|
238 | - $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
|
239 | - if ($properties) $propertyLists[$status] = $properties; |
|
240 | - break; |
|
241 | - case '{DAV:}status' : |
|
242 | - list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
|
243 | - break; |
|
244 | - |
|
245 | - } |
|
246 | - |
|
247 | - } |
|
248 | - |
|
249 | - return new self($href, $propertyLists, $statusCode); |
|
250 | - |
|
251 | - } |
|
151 | + $writer->writeElement('{DAV:}propstat', [ |
|
152 | + '{DAV:}prop' => [], |
|
153 | + '{DAV:}status' => 'HTTP/1.1 418 ' . \Sabre\HTTP\Response::$statusCodes[418] |
|
154 | + ]); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * The deserialize method is called during xml parsing. |
|
162 | + * |
|
163 | + * This method is called statictly, this is because in theory this method |
|
164 | + * may be used as a type of constructor, or factory method. |
|
165 | + * |
|
166 | + * Often you want to return an instance of the current class, but you are |
|
167 | + * free to return other data as well. |
|
168 | + * |
|
169 | + * You are responsible for advancing the reader to the next element. Not |
|
170 | + * doing anything will result in a never-ending loop. |
|
171 | + * |
|
172 | + * If you just want to skip parsing for this element altogether, you can |
|
173 | + * just call $reader->next(); |
|
174 | + * |
|
175 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
176 | + * the next element. |
|
177 | + * |
|
178 | + * @param Reader $reader |
|
179 | + * @return mixed |
|
180 | + */ |
|
181 | + static function xmlDeserialize(Reader $reader) { |
|
182 | + |
|
183 | + $reader->pushContext(); |
|
184 | + |
|
185 | + $reader->elementMap['{DAV:}propstat'] = 'Sabre\\Xml\\Element\\KeyValue'; |
|
186 | + |
|
187 | + // We are overriding the parser for {DAV:}prop. This deserializer is |
|
188 | + // almost identical to the one for Sabre\Xml\Element\KeyValue. |
|
189 | + // |
|
190 | + // The difference is that if there are any child-elements inside of |
|
191 | + // {DAV:}prop, that have no value, normally any deserializers are |
|
192 | + // called. But we don't want this, because a singular element without |
|
193 | + // child-elements implies 'no value' in {DAV:}prop, so we want to skip |
|
194 | + // deserializers and just set null for those. |
|
195 | + $reader->elementMap['{DAV:}prop'] = function(Reader $reader) { |
|
196 | + |
|
197 | + if ($reader->isEmptyElement) { |
|
198 | + $reader->next(); |
|
199 | + return []; |
|
200 | + } |
|
201 | + $values = []; |
|
202 | + $reader->read(); |
|
203 | + do { |
|
204 | + if ($reader->nodeType === Reader::ELEMENT) { |
|
205 | + $clark = $reader->getClark(); |
|
206 | + |
|
207 | + if ($reader->isEmptyElement) { |
|
208 | + $values[$clark] = null; |
|
209 | + $reader->next(); |
|
210 | + } else { |
|
211 | + $values[$clark] = $reader->parseCurrentElement()['value']; |
|
212 | + } |
|
213 | + } else { |
|
214 | + $reader->read(); |
|
215 | + } |
|
216 | + } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
217 | + $reader->read(); |
|
218 | + return $values; |
|
219 | + |
|
220 | + }; |
|
221 | + $elems = $reader->parseInnerTree(); |
|
222 | + $reader->popContext(); |
|
223 | + |
|
224 | + $href = null; |
|
225 | + $propertyLists = []; |
|
226 | + $statusCode = null; |
|
227 | + |
|
228 | + foreach ($elems as $elem) { |
|
229 | + |
|
230 | + switch ($elem['name']) { |
|
231 | + |
|
232 | + case '{DAV:}href' : |
|
233 | + $href = $elem['value']; |
|
234 | + break; |
|
235 | + case '{DAV:}propstat' : |
|
236 | + $status = $elem['value']['{DAV:}status']; |
|
237 | + list(, $status, ) = explode(' ', $status, 3); |
|
238 | + $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
|
239 | + if ($properties) $propertyLists[$status] = $properties; |
|
240 | + break; |
|
241 | + case '{DAV:}status' : |
|
242 | + list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
|
243 | + break; |
|
244 | + |
|
245 | + } |
|
246 | + |
|
247 | + } |
|
248 | + |
|
249 | + return new self($href, $propertyLists, $statusCode); |
|
250 | + |
|
251 | + } |
|
252 | 252 | |
253 | 253 | } |
@@ -99,7 +99,7 @@ |
||
99 | 99 | * the next element. |
100 | 100 | * |
101 | 101 | * @param Reader $reader |
102 | - * @return mixed |
|
102 | + * @return GetLastModified |
|
103 | 103 | */ |
104 | 104 | static function xmlDeserialize(Reader $reader) { |
105 | 105 |
@@ -2,12 +2,12 @@ |
||
2 | 2 | |
3 | 3 | namespace Sabre\DAV\Xml\Property; |
4 | 4 | |
5 | +use DateTime; |
|
6 | +use DateTimeZone; |
|
7 | +use Sabre\HTTP; |
|
5 | 8 | use Sabre\Xml\Element; |
6 | 9 | use Sabre\Xml\Reader; |
7 | 10 | use Sabre\Xml\Writer; |
8 | -use Sabre\HTTP; |
|
9 | -use DateTime; |
|
10 | -use DateTimeZone; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * This property represents the {DAV:}getlastmodified property. |
@@ -21,90 +21,90 @@ |
||
21 | 21 | */ |
22 | 22 | class GetLastModified implements Element { |
23 | 23 | |
24 | - /** |
|
25 | - * time |
|
26 | - * |
|
27 | - * @var DateTime |
|
28 | - */ |
|
29 | - public $time; |
|
30 | - |
|
31 | - /** |
|
32 | - * Constructor |
|
33 | - * |
|
34 | - * @param int|DateTime $time |
|
35 | - */ |
|
36 | - public function __construct($time) { |
|
37 | - |
|
38 | - if ($time instanceof DateTime) { |
|
39 | - $this->time = clone $time; |
|
40 | - } else { |
|
41 | - $this->time = new DateTime('@' . $time); |
|
42 | - } |
|
43 | - |
|
44 | - // Setting timezone to UTC |
|
45 | - $this->time->setTimezone(new DateTimeZone('UTC')); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * getTime |
|
51 | - * |
|
52 | - * @return DateTime |
|
53 | - */ |
|
54 | - public function getTime() { |
|
55 | - |
|
56 | - return $this->time; |
|
57 | - |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * The serialize method is called during xml writing. |
|
62 | - * |
|
63 | - * It should use the $writer argument to encode this object into XML. |
|
64 | - * |
|
65 | - * Important note: it is not needed to create the parent element. The |
|
66 | - * parent element is already created, and we only have to worry about |
|
67 | - * attributes, child elements and text (if any). |
|
68 | - * |
|
69 | - * Important note 2: If you are writing any new elements, you are also |
|
70 | - * responsible for closing them. |
|
71 | - * |
|
72 | - * @param Writer $writer |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function xmlSerialize(Writer $writer) { |
|
76 | - |
|
77 | - $writer->write( |
|
78 | - HTTP\Util::toHTTPDate($this->time) |
|
79 | - ); |
|
80 | - |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * The deserialize method is called during xml parsing. |
|
85 | - * |
|
86 | - * This method is called statictly, this is because in theory this method |
|
87 | - * may be used as a type of constructor, or factory method. |
|
88 | - * |
|
89 | - * Often you want to return an instance of the current class, but you are |
|
90 | - * free to return other data as well. |
|
91 | - * |
|
92 | - * Important note 2: You are responsible for advancing the reader to the |
|
93 | - * next element. Not doing anything will result in a never-ending loop. |
|
94 | - * |
|
95 | - * If you just want to skip parsing for this element altogether, you can |
|
96 | - * just call $reader->next(); |
|
97 | - * |
|
98 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
99 | - * the next element. |
|
100 | - * |
|
101 | - * @param Reader $reader |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - static function xmlDeserialize(Reader $reader) { |
|
105 | - |
|
106 | - return |
|
107 | - new self(new DateTime($reader->parseInnerTree())); |
|
108 | - |
|
109 | - } |
|
24 | + /** |
|
25 | + * time |
|
26 | + * |
|
27 | + * @var DateTime |
|
28 | + */ |
|
29 | + public $time; |
|
30 | + |
|
31 | + /** |
|
32 | + * Constructor |
|
33 | + * |
|
34 | + * @param int|DateTime $time |
|
35 | + */ |
|
36 | + public function __construct($time) { |
|
37 | + |
|
38 | + if ($time instanceof DateTime) { |
|
39 | + $this->time = clone $time; |
|
40 | + } else { |
|
41 | + $this->time = new DateTime('@' . $time); |
|
42 | + } |
|
43 | + |
|
44 | + // Setting timezone to UTC |
|
45 | + $this->time->setTimezone(new DateTimeZone('UTC')); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * getTime |
|
51 | + * |
|
52 | + * @return DateTime |
|
53 | + */ |
|
54 | + public function getTime() { |
|
55 | + |
|
56 | + return $this->time; |
|
57 | + |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * The serialize method is called during xml writing. |
|
62 | + * |
|
63 | + * It should use the $writer argument to encode this object into XML. |
|
64 | + * |
|
65 | + * Important note: it is not needed to create the parent element. The |
|
66 | + * parent element is already created, and we only have to worry about |
|
67 | + * attributes, child elements and text (if any). |
|
68 | + * |
|
69 | + * Important note 2: If you are writing any new elements, you are also |
|
70 | + * responsible for closing them. |
|
71 | + * |
|
72 | + * @param Writer $writer |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function xmlSerialize(Writer $writer) { |
|
76 | + |
|
77 | + $writer->write( |
|
78 | + HTTP\Util::toHTTPDate($this->time) |
|
79 | + ); |
|
80 | + |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * The deserialize method is called during xml parsing. |
|
85 | + * |
|
86 | + * This method is called statictly, this is because in theory this method |
|
87 | + * may be used as a type of constructor, or factory method. |
|
88 | + * |
|
89 | + * Often you want to return an instance of the current class, but you are |
|
90 | + * free to return other data as well. |
|
91 | + * |
|
92 | + * Important note 2: You are responsible for advancing the reader to the |
|
93 | + * next element. Not doing anything will result in a never-ending loop. |
|
94 | + * |
|
95 | + * If you just want to skip parsing for this element altogether, you can |
|
96 | + * just call $reader->next(); |
|
97 | + * |
|
98 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
99 | + * the next element. |
|
100 | + * |
|
101 | + * @param Reader $reader |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + static function xmlDeserialize(Reader $reader) { |
|
105 | + |
|
106 | + return |
|
107 | + new self(new DateTime($reader->parseInnerTree())); |
|
108 | + |
|
109 | + } |
|
110 | 110 | } |
@@ -54,7 +54,7 @@ |
||
54 | 54 | * the next element. |
55 | 55 | * |
56 | 56 | * @param Reader $reader |
57 | - * @return mixed |
|
57 | + * @return Lock |
|
58 | 58 | */ |
59 | 59 | static function xmlDeserialize(Reader $reader) { |
60 | 60 |
@@ -20,62 +20,62 @@ |
||
20 | 20 | */ |
21 | 21 | class Lock implements XmlDeserializable { |
22 | 22 | |
23 | - /** |
|
24 | - * Owner of the lock |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $owner; |
|
23 | + /** |
|
24 | + * Owner of the lock |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $owner; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Scope of the lock. |
|
32 | - * |
|
33 | - * Either LockInfo::SHARED or LockInfo::EXCLUSIVE |
|
34 | - * @var int |
|
35 | - */ |
|
36 | - public $scope; |
|
30 | + /** |
|
31 | + * Scope of the lock. |
|
32 | + * |
|
33 | + * Either LockInfo::SHARED or LockInfo::EXCLUSIVE |
|
34 | + * @var int |
|
35 | + */ |
|
36 | + public $scope; |
|
37 | 37 | |
38 | - /** |
|
39 | - * The deserialize method is called during xml parsing. |
|
40 | - * |
|
41 | - * This method is called statictly, this is because in theory this method |
|
42 | - * may be used as a type of constructor, or factory method. |
|
43 | - * |
|
44 | - * Often you want to return an instance of the current class, but you are |
|
45 | - * free to return other data as well. |
|
46 | - * |
|
47 | - * You are responsible for advancing the reader to the next element. Not |
|
48 | - * doing anything will result in a never-ending loop. |
|
49 | - * |
|
50 | - * If you just want to skip parsing for this element altogether, you can |
|
51 | - * just call $reader->next(); |
|
52 | - * |
|
53 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
54 | - * the next element. |
|
55 | - * |
|
56 | - * @param Reader $reader |
|
57 | - * @return mixed |
|
58 | - */ |
|
59 | - static function xmlDeserialize(Reader $reader) { |
|
38 | + /** |
|
39 | + * The deserialize method is called during xml parsing. |
|
40 | + * |
|
41 | + * This method is called statictly, this is because in theory this method |
|
42 | + * may be used as a type of constructor, or factory method. |
|
43 | + * |
|
44 | + * Often you want to return an instance of the current class, but you are |
|
45 | + * free to return other data as well. |
|
46 | + * |
|
47 | + * You are responsible for advancing the reader to the next element. Not |
|
48 | + * doing anything will result in a never-ending loop. |
|
49 | + * |
|
50 | + * If you just want to skip parsing for this element altogether, you can |
|
51 | + * just call $reader->next(); |
|
52 | + * |
|
53 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
54 | + * the next element. |
|
55 | + * |
|
56 | + * @param Reader $reader |
|
57 | + * @return mixed |
|
58 | + */ |
|
59 | + static function xmlDeserialize(Reader $reader) { |
|
60 | 60 | |
61 | - $reader->pushContext(); |
|
62 | - $reader->elementMap['{DAV:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment'; |
|
61 | + $reader->pushContext(); |
|
62 | + $reader->elementMap['{DAV:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment'; |
|
63 | 63 | |
64 | - $values = KeyValue::xmlDeserialize($reader); |
|
64 | + $values = KeyValue::xmlDeserialize($reader); |
|
65 | 65 | |
66 | - $reader->popContext(); |
|
66 | + $reader->popContext(); |
|
67 | 67 | |
68 | - $new = new self(); |
|
69 | - $new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null; |
|
70 | - $new->scope = LockInfo::SHARED; |
|
68 | + $new = new self(); |
|
69 | + $new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null; |
|
70 | + $new->scope = LockInfo::SHARED; |
|
71 | 71 | |
72 | - if (isset($values['{DAV:}lockscope'])) { |
|
73 | - foreach ($values['{DAV:}lockscope'] as $elem) { |
|
74 | - if ($elem['name'] === '{DAV:}exclusive') $new->scope = LockInfo::EXCLUSIVE; |
|
75 | - } |
|
76 | - } |
|
77 | - return $new; |
|
72 | + if (isset($values['{DAV:}lockscope'])) { |
|
73 | + foreach ($values['{DAV:}lockscope'] as $elem) { |
|
74 | + if ($elem['name'] === '{DAV:}exclusive') $new->scope = LockInfo::EXCLUSIVE; |
|
75 | + } |
|
76 | + } |
|
77 | + return $new; |
|
78 | 78 | |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
@@ -71,7 +71,9 @@ |
||
71 | 71 | |
72 | 72 | if (isset($values['{DAV:}lockscope'])) { |
73 | 73 | foreach ($values['{DAV:}lockscope'] as $elem) { |
74 | - if ($elem['name'] === '{DAV:}exclusive') $new->scope = LockInfo::EXCLUSIVE; |
|
74 | + if ($elem['name'] === '{DAV:}exclusive') { |
|
75 | + $new->scope = LockInfo::EXCLUSIVE; |
|
76 | + } |
|
75 | 77 | } |
76 | 78 | } |
77 | 79 | return $new; |
@@ -56,7 +56,7 @@ |
||
56 | 56 | * the next element. |
57 | 57 | * |
58 | 58 | * @param Reader $reader |
59 | - * @return mixed |
|
59 | + * @return MkCol |
|
60 | 60 | */ |
61 | 61 | static function xmlDeserialize(Reader $reader) { |
62 | 62 |
@@ -18,65 +18,65 @@ |
||
18 | 18 | */ |
19 | 19 | class MkCol implements XmlDeserializable { |
20 | 20 | |
21 | - /** |
|
22 | - * The list of properties that will be set. |
|
23 | - * |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $properties = []; |
|
21 | + /** |
|
22 | + * The list of properties that will be set. |
|
23 | + * |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $properties = []; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Returns a key=>value array with properties that are supposed to get set |
|
30 | - * during creation of the new collection. |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function getProperties() { |
|
28 | + /** |
|
29 | + * Returns a key=>value array with properties that are supposed to get set |
|
30 | + * during creation of the new collection. |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function getProperties() { |
|
35 | 35 | |
36 | - return $this->properties; |
|
36 | + return $this->properties; |
|
37 | 37 | |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * The deserialize method is called during xml parsing. |
|
42 | - * |
|
43 | - * This method is called statictly, this is because in theory this method |
|
44 | - * may be used as a type of constructor, or factory method. |
|
45 | - * |
|
46 | - * Often you want to return an instance of the current class, but you are |
|
47 | - * free to return other data as well. |
|
48 | - * |
|
49 | - * You are responsible for advancing the reader to the next element. Not |
|
50 | - * doing anything will result in a never-ending loop. |
|
51 | - * |
|
52 | - * If you just want to skip parsing for this element altogether, you can |
|
53 | - * just call $reader->next(); |
|
54 | - * |
|
55 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
56 | - * the next element. |
|
57 | - * |
|
58 | - * @param Reader $reader |
|
59 | - * @return mixed |
|
60 | - */ |
|
61 | - static function xmlDeserialize(Reader $reader) { |
|
40 | + /** |
|
41 | + * The deserialize method is called during xml parsing. |
|
42 | + * |
|
43 | + * This method is called statictly, this is because in theory this method |
|
44 | + * may be used as a type of constructor, or factory method. |
|
45 | + * |
|
46 | + * Often you want to return an instance of the current class, but you are |
|
47 | + * free to return other data as well. |
|
48 | + * |
|
49 | + * You are responsible for advancing the reader to the next element. Not |
|
50 | + * doing anything will result in a never-ending loop. |
|
51 | + * |
|
52 | + * If you just want to skip parsing for this element altogether, you can |
|
53 | + * just call $reader->next(); |
|
54 | + * |
|
55 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
56 | + * the next element. |
|
57 | + * |
|
58 | + * @param Reader $reader |
|
59 | + * @return mixed |
|
60 | + */ |
|
61 | + static function xmlDeserialize(Reader $reader) { |
|
62 | 62 | |
63 | - $self = new self(); |
|
63 | + $self = new self(); |
|
64 | 64 | |
65 | - $elementMap = $reader->elementMap; |
|
66 | - $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop'; |
|
67 | - $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue'; |
|
68 | - $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue'; |
|
65 | + $elementMap = $reader->elementMap; |
|
66 | + $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop'; |
|
67 | + $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue'; |
|
68 | + $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue'; |
|
69 | 69 | |
70 | - $elems = $reader->parseInnerTree($elementMap); |
|
70 | + $elems = $reader->parseInnerTree($elementMap); |
|
71 | 71 | |
72 | - foreach ($elems as $elem) { |
|
73 | - if ($elem['name'] === '{DAV:}set') { |
|
74 | - $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']); |
|
75 | - } |
|
76 | - } |
|
72 | + foreach ($elems as $elem) { |
|
73 | + if ($elem['name'] === '{DAV:}set') { |
|
74 | + $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $self; |
|
78 | + return $self; |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | * the next element. |
53 | 53 | * |
54 | 54 | * @param Reader $reader |
55 | - * @return mixed |
|
55 | + * @return PropFind |
|
56 | 56 | */ |
57 | 57 | static function xmlDeserialize(Reader $reader) { |
58 | 58 |
@@ -19,65 +19,65 @@ |
||
19 | 19 | */ |
20 | 20 | class PropFind implements XmlDeserializable { |
21 | 21 | |
22 | - /** |
|
23 | - * If this is set to true, this was an 'allprop' request. |
|
24 | - * |
|
25 | - * @var bool |
|
26 | - */ |
|
27 | - public $allProp = false; |
|
28 | - |
|
29 | - /** |
|
30 | - * The property list |
|
31 | - * |
|
32 | - * @var null|array |
|
33 | - */ |
|
34 | - public $properties; |
|
35 | - |
|
36 | - /** |
|
37 | - * The deserialize method is called during xml parsing. |
|
38 | - * |
|
39 | - * This method is called statictly, this is because in theory this method |
|
40 | - * may be used as a type of constructor, or factory method. |
|
41 | - * |
|
42 | - * Often you want to return an instance of the current class, but you are |
|
43 | - * free to return other data as well. |
|
44 | - * |
|
45 | - * You are responsible for advancing the reader to the next element. Not |
|
46 | - * doing anything will result in a never-ending loop. |
|
47 | - * |
|
48 | - * If you just want to skip parsing for this element altogether, you can |
|
49 | - * just call $reader->next(); |
|
50 | - * |
|
51 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
52 | - * the next element. |
|
53 | - * |
|
54 | - * @param Reader $reader |
|
55 | - * @return mixed |
|
56 | - */ |
|
57 | - static function xmlDeserialize(Reader $reader) { |
|
58 | - |
|
59 | - $self = new self(); |
|
60 | - |
|
61 | - $reader->pushContext(); |
|
62 | - $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
63 | - |
|
64 | - foreach (KeyValue::xmlDeserialize($reader) as $k => $v) { |
|
65 | - |
|
66 | - switch ($k) { |
|
67 | - case '{DAV:}prop' : |
|
68 | - $self->properties = $v; |
|
69 | - break; |
|
70 | - case '{DAV:}allprop' : |
|
71 | - $self->allProp = true; |
|
72 | - |
|
73 | - } |
|
74 | - |
|
75 | - } |
|
76 | - |
|
77 | - $reader->popContext(); |
|
78 | - |
|
79 | - return $self; |
|
80 | - |
|
81 | - } |
|
22 | + /** |
|
23 | + * If this is set to true, this was an 'allprop' request. |
|
24 | + * |
|
25 | + * @var bool |
|
26 | + */ |
|
27 | + public $allProp = false; |
|
28 | + |
|
29 | + /** |
|
30 | + * The property list |
|
31 | + * |
|
32 | + * @var null|array |
|
33 | + */ |
|
34 | + public $properties; |
|
35 | + |
|
36 | + /** |
|
37 | + * The deserialize method is called during xml parsing. |
|
38 | + * |
|
39 | + * This method is called statictly, this is because in theory this method |
|
40 | + * may be used as a type of constructor, or factory method. |
|
41 | + * |
|
42 | + * Often you want to return an instance of the current class, but you are |
|
43 | + * free to return other data as well. |
|
44 | + * |
|
45 | + * You are responsible for advancing the reader to the next element. Not |
|
46 | + * doing anything will result in a never-ending loop. |
|
47 | + * |
|
48 | + * If you just want to skip parsing for this element altogether, you can |
|
49 | + * just call $reader->next(); |
|
50 | + * |
|
51 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
52 | + * the next element. |
|
53 | + * |
|
54 | + * @param Reader $reader |
|
55 | + * @return mixed |
|
56 | + */ |
|
57 | + static function xmlDeserialize(Reader $reader) { |
|
58 | + |
|
59 | + $self = new self(); |
|
60 | + |
|
61 | + $reader->pushContext(); |
|
62 | + $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
63 | + |
|
64 | + foreach (KeyValue::xmlDeserialize($reader) as $k => $v) { |
|
65 | + |
|
66 | + switch ($k) { |
|
67 | + case '{DAV:}prop' : |
|
68 | + $self->properties = $v; |
|
69 | + break; |
|
70 | + case '{DAV:}allprop' : |
|
71 | + $self->allProp = true; |
|
72 | + |
|
73 | + } |
|
74 | + |
|
75 | + } |
|
76 | + |
|
77 | + $reader->popContext(); |
|
78 | + |
|
79 | + return $self; |
|
80 | + |
|
81 | + } |
|
82 | 82 | |
83 | 83 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | * the next element. |
85 | 85 | * |
86 | 86 | * @param Reader $reader |
87 | - * @return mixed |
|
87 | + * @return PropPatch |
|
88 | 88 | */ |
89 | 89 | static function xmlDeserialize(Reader $reader) { |
90 | 90 |
@@ -19,100 +19,100 @@ |
||
19 | 19 | */ |
20 | 20 | class PropPatch implements Element { |
21 | 21 | |
22 | - /** |
|
23 | - * The list of properties that will be updated and removed. |
|
24 | - * |
|
25 | - * If a property will be removed, it's value will be set to null. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - public $properties = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * The xmlSerialize metod is called during xml writing. |
|
33 | - * |
|
34 | - * Use the $writer argument to write its own xml serialization. |
|
35 | - * |
|
36 | - * An important note: do _not_ create a parent element. Any element |
|
37 | - * implementing XmlSerializble should only ever write what's considered |
|
38 | - * its 'inner xml'. |
|
39 | - * |
|
40 | - * The parent of the current element is responsible for writing a |
|
41 | - * containing element. |
|
42 | - * |
|
43 | - * This allows serializers to be re-used for different element names. |
|
44 | - * |
|
45 | - * If you are opening new elements, you must also close them again. |
|
46 | - * |
|
47 | - * @param Writer $writer |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function xmlSerialize(Writer $writer) { |
|
51 | - |
|
52 | - foreach ($this->properties as $propertyName => $propertyValue) { |
|
53 | - |
|
54 | - if (is_null($propertyValue)) { |
|
55 | - $writer->startElement("{DAV:}remove"); |
|
56 | - $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); |
|
57 | - $writer->endElement(); |
|
58 | - } else { |
|
59 | - $writer->startElement("{DAV:}set"); |
|
60 | - $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); |
|
61 | - $writer->endElement(); |
|
62 | - } |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * The deserialize method is called during xml parsing. |
|
70 | - * |
|
71 | - * This method is called statictly, this is because in theory this method |
|
72 | - * may be used as a type of constructor, or factory method. |
|
73 | - * |
|
74 | - * Often you want to return an instance of the current class, but you are |
|
75 | - * free to return other data as well. |
|
76 | - * |
|
77 | - * You are responsible for advancing the reader to the next element. Not |
|
78 | - * doing anything will result in a never-ending loop. |
|
79 | - * |
|
80 | - * If you just want to skip parsing for this element altogether, you can |
|
81 | - * just call $reader->next(); |
|
82 | - * |
|
83 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
84 | - * the next element. |
|
85 | - * |
|
86 | - * @param Reader $reader |
|
87 | - * @return mixed |
|
88 | - */ |
|
89 | - static function xmlDeserialize(Reader $reader) { |
|
90 | - |
|
91 | - $self = new self(); |
|
92 | - |
|
93 | - $elementMap = $reader->elementMap; |
|
94 | - $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop'; |
|
95 | - $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue'; |
|
96 | - $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue'; |
|
97 | - |
|
98 | - $elems = $reader->parseInnerTree($elementMap); |
|
99 | - |
|
100 | - foreach ($elems as $elem) { |
|
101 | - if ($elem['name'] === '{DAV:}set') { |
|
102 | - $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']); |
|
103 | - } |
|
104 | - if ($elem['name'] === '{DAV:}remove') { |
|
105 | - |
|
106 | - // Ensuring there are no values. |
|
107 | - foreach ($elem['value']['{DAV:}prop'] as $remove => $value) { |
|
108 | - $self->properties[$remove] = null; |
|
109 | - } |
|
110 | - |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - return $self; |
|
115 | - |
|
116 | - } |
|
22 | + /** |
|
23 | + * The list of properties that will be updated and removed. |
|
24 | + * |
|
25 | + * If a property will be removed, it's value will be set to null. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + public $properties = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * The xmlSerialize metod is called during xml writing. |
|
33 | + * |
|
34 | + * Use the $writer argument to write its own xml serialization. |
|
35 | + * |
|
36 | + * An important note: do _not_ create a parent element. Any element |
|
37 | + * implementing XmlSerializble should only ever write what's considered |
|
38 | + * its 'inner xml'. |
|
39 | + * |
|
40 | + * The parent of the current element is responsible for writing a |
|
41 | + * containing element. |
|
42 | + * |
|
43 | + * This allows serializers to be re-used for different element names. |
|
44 | + * |
|
45 | + * If you are opening new elements, you must also close them again. |
|
46 | + * |
|
47 | + * @param Writer $writer |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function xmlSerialize(Writer $writer) { |
|
51 | + |
|
52 | + foreach ($this->properties as $propertyName => $propertyValue) { |
|
53 | + |
|
54 | + if (is_null($propertyValue)) { |
|
55 | + $writer->startElement("{DAV:}remove"); |
|
56 | + $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); |
|
57 | + $writer->endElement(); |
|
58 | + } else { |
|
59 | + $writer->startElement("{DAV:}set"); |
|
60 | + $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); |
|
61 | + $writer->endElement(); |
|
62 | + } |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * The deserialize method is called during xml parsing. |
|
70 | + * |
|
71 | + * This method is called statictly, this is because in theory this method |
|
72 | + * may be used as a type of constructor, or factory method. |
|
73 | + * |
|
74 | + * Often you want to return an instance of the current class, but you are |
|
75 | + * free to return other data as well. |
|
76 | + * |
|
77 | + * You are responsible for advancing the reader to the next element. Not |
|
78 | + * doing anything will result in a never-ending loop. |
|
79 | + * |
|
80 | + * If you just want to skip parsing for this element altogether, you can |
|
81 | + * just call $reader->next(); |
|
82 | + * |
|
83 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
84 | + * the next element. |
|
85 | + * |
|
86 | + * @param Reader $reader |
|
87 | + * @return mixed |
|
88 | + */ |
|
89 | + static function xmlDeserialize(Reader $reader) { |
|
90 | + |
|
91 | + $self = new self(); |
|
92 | + |
|
93 | + $elementMap = $reader->elementMap; |
|
94 | + $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop'; |
|
95 | + $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue'; |
|
96 | + $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue'; |
|
97 | + |
|
98 | + $elems = $reader->parseInnerTree($elementMap); |
|
99 | + |
|
100 | + foreach ($elems as $elem) { |
|
101 | + if ($elem['name'] === '{DAV:}set') { |
|
102 | + $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']); |
|
103 | + } |
|
104 | + if ($elem['name'] === '{DAV:}remove') { |
|
105 | + |
|
106 | + // Ensuring there are no values. |
|
107 | + foreach ($elem['value']['{DAV:}prop'] as $remove => $value) { |
|
108 | + $self->properties[$remove] = null; |
|
109 | + } |
|
110 | + |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + return $self; |
|
115 | + |
|
116 | + } |
|
117 | 117 | |
118 | 118 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | * the next element. |
68 | 68 | * |
69 | 69 | * @param Reader $reader |
70 | - * @return mixed |
|
70 | + * @return SyncCollectionReport |
|
71 | 71 | */ |
72 | 72 | static function xmlDeserialize(Reader $reader) { |
73 | 73 |
@@ -2,10 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace Sabre\DAV\Xml\Request; |
4 | 4 | |
5 | +use Sabre\DAV\Exception\BadRequest; |
|
6 | +use Sabre\Xml\Element\KeyValue; |
|
5 | 7 | use Sabre\Xml\Reader; |
6 | 8 | use Sabre\Xml\XmlDeserializable; |
7 | -use Sabre\Xml\Element\KeyValue; |
|
8 | -use Sabre\DAV\Exception\BadRequest; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * SyncCollection request parser. |
@@ -20,103 +20,103 @@ |
||
20 | 20 | */ |
21 | 21 | class SyncCollectionReport implements XmlDeserializable { |
22 | 22 | |
23 | - /** |
|
24 | - * The sync-token the client supplied for the report. |
|
25 | - * |
|
26 | - * @var string|null |
|
27 | - */ |
|
28 | - public $syncToken; |
|
29 | - |
|
30 | - /** |
|
31 | - * The 'depth' of the sync the client is interested in. |
|
32 | - * |
|
33 | - * @var int |
|
34 | - */ |
|
35 | - public $syncLevel; |
|
36 | - |
|
37 | - /** |
|
38 | - * Maximum amount of items returned. |
|
39 | - * |
|
40 | - * @var int|null |
|
41 | - */ |
|
42 | - public $limit; |
|
43 | - |
|
44 | - /** |
|
45 | - * The list of properties that are being requested for every change. |
|
46 | - * |
|
47 | - * @var null|array |
|
48 | - */ |
|
49 | - public $properties; |
|
50 | - |
|
51 | - /** |
|
52 | - * The deserialize method is called during xml parsing. |
|
53 | - * |
|
54 | - * This method is called statictly, this is because in theory this method |
|
55 | - * may be used as a type of constructor, or factory method. |
|
56 | - * |
|
57 | - * Often you want to return an instance of the current class, but you are |
|
58 | - * free to return other data as well. |
|
59 | - * |
|
60 | - * You are responsible for advancing the reader to the next element. Not |
|
61 | - * doing anything will result in a never-ending loop. |
|
62 | - * |
|
63 | - * If you just want to skip parsing for this element altogether, you can |
|
64 | - * just call $reader->next(); |
|
65 | - * |
|
66 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
67 | - * the next element. |
|
68 | - * |
|
69 | - * @param Reader $reader |
|
70 | - * @return mixed |
|
71 | - */ |
|
72 | - static function xmlDeserialize(Reader $reader) { |
|
73 | - |
|
74 | - $self = new self(); |
|
75 | - |
|
76 | - $reader->pushContext(); |
|
77 | - |
|
78 | - $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
79 | - $elems = KeyValue::xmlDeserialize($reader); |
|
80 | - |
|
81 | - $reader->popContext(); |
|
82 | - |
|
83 | - $required = [ |
|
84 | - '{DAV:}sync-token', |
|
85 | - '{DAV:}prop', |
|
86 | - ]; |
|
87 | - |
|
88 | - foreach ($required as $elem) { |
|
89 | - if (!array_key_exists($elem, $elems)) { |
|
90 | - throw new BadRequest('The ' . $elem . ' element in the {DAV:}sync-collection report is required'); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - $self->properties = $elems['{DAV:}prop']; |
|
96 | - $self->syncToken = $elems['{DAV:}sync-token']; |
|
97 | - |
|
98 | - if (isset($elems['{DAV:}limit'])) { |
|
99 | - $nresults = null; |
|
100 | - foreach ($elems['{DAV:}limit'] as $child) { |
|
101 | - if ($child['name'] === '{DAV:}nresults') { |
|
102 | - $nresults = (int)$child['value']; |
|
103 | - } |
|
104 | - } |
|
105 | - $self->limit = $nresults; |
|
106 | - } |
|
107 | - |
|
108 | - if (isset($elems['{DAV:}sync-level'])) { |
|
109 | - |
|
110 | - $value = $elems['{DAV:}sync-level']; |
|
111 | - if ($value === 'infinity') { |
|
112 | - $value = \Sabre\DAV\Server::DEPTH_INFINITY; |
|
113 | - } |
|
114 | - $self->syncLevel = $value; |
|
115 | - |
|
116 | - } |
|
117 | - |
|
118 | - return $self; |
|
119 | - |
|
120 | - } |
|
23 | + /** |
|
24 | + * The sync-token the client supplied for the report. |
|
25 | + * |
|
26 | + * @var string|null |
|
27 | + */ |
|
28 | + public $syncToken; |
|
29 | + |
|
30 | + /** |
|
31 | + * The 'depth' of the sync the client is interested in. |
|
32 | + * |
|
33 | + * @var int |
|
34 | + */ |
|
35 | + public $syncLevel; |
|
36 | + |
|
37 | + /** |
|
38 | + * Maximum amount of items returned. |
|
39 | + * |
|
40 | + * @var int|null |
|
41 | + */ |
|
42 | + public $limit; |
|
43 | + |
|
44 | + /** |
|
45 | + * The list of properties that are being requested for every change. |
|
46 | + * |
|
47 | + * @var null|array |
|
48 | + */ |
|
49 | + public $properties; |
|
50 | + |
|
51 | + /** |
|
52 | + * The deserialize method is called during xml parsing. |
|
53 | + * |
|
54 | + * This method is called statictly, this is because in theory this method |
|
55 | + * may be used as a type of constructor, or factory method. |
|
56 | + * |
|
57 | + * Often you want to return an instance of the current class, but you are |
|
58 | + * free to return other data as well. |
|
59 | + * |
|
60 | + * You are responsible for advancing the reader to the next element. Not |
|
61 | + * doing anything will result in a never-ending loop. |
|
62 | + * |
|
63 | + * If you just want to skip parsing for this element altogether, you can |
|
64 | + * just call $reader->next(); |
|
65 | + * |
|
66 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
67 | + * the next element. |
|
68 | + * |
|
69 | + * @param Reader $reader |
|
70 | + * @return mixed |
|
71 | + */ |
|
72 | + static function xmlDeserialize(Reader $reader) { |
|
73 | + |
|
74 | + $self = new self(); |
|
75 | + |
|
76 | + $reader->pushContext(); |
|
77 | + |
|
78 | + $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
79 | + $elems = KeyValue::xmlDeserialize($reader); |
|
80 | + |
|
81 | + $reader->popContext(); |
|
82 | + |
|
83 | + $required = [ |
|
84 | + '{DAV:}sync-token', |
|
85 | + '{DAV:}prop', |
|
86 | + ]; |
|
87 | + |
|
88 | + foreach ($required as $elem) { |
|
89 | + if (!array_key_exists($elem, $elems)) { |
|
90 | + throw new BadRequest('The ' . $elem . ' element in the {DAV:}sync-collection report is required'); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + $self->properties = $elems['{DAV:}prop']; |
|
96 | + $self->syncToken = $elems['{DAV:}sync-token']; |
|
97 | + |
|
98 | + if (isset($elems['{DAV:}limit'])) { |
|
99 | + $nresults = null; |
|
100 | + foreach ($elems['{DAV:}limit'] as $child) { |
|
101 | + if ($child['name'] === '{DAV:}nresults') { |
|
102 | + $nresults = (int)$child['value']; |
|
103 | + } |
|
104 | + } |
|
105 | + $self->limit = $nresults; |
|
106 | + } |
|
107 | + |
|
108 | + if (isset($elems['{DAV:}sync-level'])) { |
|
109 | + |
|
110 | + $value = $elems['{DAV:}sync-level']; |
|
111 | + if ($value === 'infinity') { |
|
112 | + $value = \Sabre\DAV\Server::DEPTH_INFINITY; |
|
113 | + } |
|
114 | + $self->syncLevel = $value; |
|
115 | + |
|
116 | + } |
|
117 | + |
|
118 | + return $self; |
|
119 | + |
|
120 | + } |
|
121 | 121 | |
122 | 122 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | $reader->pushContext(); |
77 | 77 | |
78 | - $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
78 | + $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
79 | 79 | $elems = KeyValue::xmlDeserialize($reader); |
80 | 80 | |
81 | 81 | $reader->popContext(); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $nresults = null; |
100 | 100 | foreach ($elems['{DAV:}limit'] as $child) { |
101 | 101 | if ($child['name'] === '{DAV:}nresults') { |
102 | - $nresults = (int)$child['value']; |
|
102 | + $nresults = (int) $child['value']; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | $self->limit = $nresults; |