ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PropFind.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\DAV;
4
11class PropFind {
12
16 const NORMAL = 0;
17
27 const ALLPROPS = 1;
28
33 const PROPNAME = 2;
34
43 function __construct($path, array $properties, $depth = 0, $requestType = self::NORMAL) {
44
45 $this->path = $path;
46 $this->properties = $properties;
47 $this->depth = $depth;
48 $this->requestType = $requestType;
49
50 if ($requestType === self::ALLPROPS) {
51 $this->properties = [
52 '{DAV:}getlastmodified',
53 '{DAV:}getcontentlength',
54 '{DAV:}resourcetype',
55 '{DAV:}quota-used-bytes',
56 '{DAV:}quota-available-bytes',
57 '{DAV:}getetag',
58 '{DAV:}getcontenttype',
59 ];
60 }
61
62 foreach ($this->properties as $propertyName) {
63
64 // Seeding properties with 404's.
65 $this->result[$propertyName] = [404, null];
66
67 }
68 $this->itemsLeft = count($this->result);
69
70 }
71
94 function handle($propertyName, $valueOrCallBack) {
95
96 if ($this->itemsLeft && isset($this->result[$propertyName]) && $this->result[$propertyName][0] === 404) {
97 if (is_callable($valueOrCallBack)) {
98 $value = $valueOrCallBack();
99 } else {
100 $value = $valueOrCallBack;
101 }
102 if (!is_null($value)) {
103 $this->itemsLeft--;
104 $this->result[$propertyName] = [200, $value];
105 }
106 }
107
108 }
109
121 function set($propertyName, $value, $status = null) {
122
123 if (is_null($status)) {
124 $status = is_null($value) ? 404 : 200;
125 }
126 // If this is an ALLPROPS request and the property is
127 // unknown, add it to the result; else ignore it:
128 if (!isset($this->result[$propertyName])) {
129 if ($this->requestType === self::ALLPROPS) {
130 $this->result[$propertyName] = [$status, $value];
131 }
132 return;
133 }
134 if ($status !== 404 && $this->result[$propertyName][0] === 404) {
135 $this->itemsLeft--;
136 } elseif ($status === 404 && $this->result[$propertyName][0] !== 404) {
137 $this->itemsLeft++;
138 }
139 $this->result[$propertyName] = [$status, $value];
140
141 }
142
149 function get($propertyName) {
150
151 return isset($this->result[$propertyName]) ? $this->result[$propertyName][1] : null;
152
153 }
154
164 function getStatus($propertyName) {
165
166 return isset($this->result[$propertyName]) ? $this->result[$propertyName][0] : null;
167
168 }
169
176 function setPath($path) {
177
178 $this->path = $path;
179
180 }
181
187 function getPath() {
188
189 return $this->path;
190
191 }
192
198 function getDepth() {
199
200 return $this->depth;
201
202 }
203
210 function setDepth($depth) {
211
212 $this->depth = $depth;
213
214 }
215
222 function get404Properties() {
223
224 if ($this->itemsLeft === 0) {
225 return [];
226 }
227 $result = [];
228 foreach ($this->result as $propertyName => $stuff) {
229 if ($stuff[0] === 404) {
230 $result[] = $propertyName;
231 }
232 }
233 return $result;
234
235 }
236
245
246 return $this->properties;
247
248 }
249
255 function isAllProps() {
256
257 return $this->requestType === self::ALLPROPS;
258
259 }
260
274
275 $r = [
276 200 => [],
277 404 => [],
278 ];
279 foreach ($this->result as $propertyName => $info) {
280 if (!isset($r[$info[0]])) {
281 $r[$info[0]] = [$propertyName => $info[1]];
282 } else {
283 $r[$info[0]][$propertyName] = $info[1];
284 }
285 }
286 // Removing the 404's for multi-status requests.
287 if ($this->requestType === self::ALLPROPS) unset($r[404]);
288 return $r;
289
290 }
291
297 protected $path;
298
307 protected $depth = 0;
308
312 protected $requestType;
313
319 protected $properties = [];
320
337 protected $result = [];
338
345 protected $itemsLeft;
346
347}
An exception for terminatinating execution or to throw for unit testing.
This class holds all the information about a PROPFIND request.
Definition: PropFind.php:11
getResultForMultiStatus()
Returns a result array that's often used in multistatus responses.
Definition: PropFind.php:273
const PROPNAME
A propname request.
Definition: PropFind.php:33
getDepth()
Returns the depth of this propfind request.
Definition: PropFind.php:198
const NORMAL
A normal propfind.
Definition: PropFind.php:16
const ALLPROPS
An allprops request.
Definition: PropFind.php:27
get404Properties()
Returns all propertynames that have a 404 status, and thus don't have a value yet.
Definition: PropFind.php:222
getPath()
Returns the path this PROPFIND request is for.
Definition: PropFind.php:187
setPath($path)
Updates the path for this PROPFIND.
Definition: PropFind.php:176
setDepth($depth)
Updates the depth of this propfind request.
Definition: PropFind.php:210
isAllProps()
Returns true if this was an '{DAV:}allprops' request.
Definition: PropFind.php:255
getStatus($propertyName)
Returns the current status code for a property name.
Definition: PropFind.php:164
$requestType
The type of request.
Definition: PropFind.php:312
handle($propertyName, $valueOrCallBack)
Handles a specific property.
Definition: PropFind.php:94
__construct($path, array $properties, $depth=0, $requestType=self::NORMAL)
Creates the PROPFIND object.
Definition: PropFind.php:43
getRequestedProperties()
Returns the full list of requested properties.
Definition: PropFind.php:244
$r
Definition: example_031.php:79
$info
Definition: index.php:5