ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\DAV\PropPatch Class Reference

This class represents a set of properties that are going to be updated. More...

+ Inheritance diagram for Sabre\DAV\PropPatch:
+ Collaboration diagram for Sabre\DAV\PropPatch:

Public Member Functions

 __construct (array $mutations)
 Constructor. More...
 
 handle ($properties, callable $callback)
 Call this function if you wish to handle updating certain properties. More...
 
 handleRemaining (callable $callback)
 Call this function if you wish to handle all properties that haven't been handled by anything else yet. More...
 
 setResultCode ($properties, $resultCode)
 Sets the result code for one or more properties. More...
 
 setRemainingResultCode ($resultCode)
 Sets the result code for all properties that did not have a result yet. More...
 
 getRemainingMutations ()
 Returns the list of properties that don't have a result code yet. More...
 
 getRemainingValues ()
 Returns the list of properties that don't have a result code yet. More...
 
 commit ()
 Performs the actual update, and calls all callbacks. More...
 
 getResult ()
 Returns the result of the operation. More...
 
 getMutations ()
 Returns the full list of mutations. More...
 

Protected Attributes

 $mutations
 
 $result = []
 
 $propertyUpdateCallbacks = []
 
 $failed = false
 

Private Member Functions

 doCallBackSingleProp ($propertyName, callable $callback)
 Executes a property callback with the single-property syntax. More...
 
 doCallBackMultiProp (array $propertyList, callable $callback)
 Executes a property callback with the multi-property syntax. More...
 

Detailed Description

This class represents a set of properties that are going to be updated.

Usually this is simply a PROPPATCH request, but it can also be used for internal updates.

Property updates must always be atomic. This means that a property update must either completely succeed, or completely fail.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License

Definition at line 20 of file PropPatch.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\DAV\PropPatch::__construct ( array  $mutations)

Constructor.

Parameters
array$mutationsA list of updates

Definition at line 59 of file PropPatch.php.

59 {
60
61 $this->mutations = $mutations;
62
63 }

References Sabre\DAV\PropPatch\$mutations.

Member Function Documentation

◆ commit()

Sabre\DAV\PropPatch::commit ( )

Performs the actual update, and calls all callbacks.

This method returns true or false depending on if the operation was successful.

Returns
bool

If anywhere in this operation updating a property failed, we must update all other properties accordingly.

Definition at line 225 of file PropPatch.php.

225 {
226
227 // First we validate if every property has a handler
228 foreach ($this->mutations as $propertyName => $value) {
229
230 if (!isset($this->result[$propertyName])) {
231 $this->failed = true;
232 $this->result[$propertyName] = 403;
233 }
234
235 }
236
237 foreach ($this->propertyUpdateCallbacks as $callbackInfo) {
238
239 if ($this->failed) {
240 break;
241 }
242 if (is_string($callbackInfo[0])) {
243 $this->doCallbackSingleProp($callbackInfo[0], $callbackInfo[1]);
244 } else {
245 $this->doCallbackMultiProp($callbackInfo[0], $callbackInfo[1]);
246 }
247
248 }
249
254 if ($this->failed) {
255
256 foreach ($this->result as $propertyName => $status) {
257 if ($status === 202) {
258 // Failed dependency
259 $this->result[$propertyName] = 424;
260 }
261 }
262
263 }
264
265 return !$this->failed;
266
267 }

References Sabre\DAV\PropPatch\$failed.

Referenced by Sabre\DAV\Server\createCollection().

+ Here is the caller graph for this function:

◆ doCallBackMultiProp()

Sabre\DAV\PropPatch::doCallBackMultiProp ( array  $propertyList,
callable  $callback 
)
private

Executes a property callback with the multi-property syntax.

Parameters
array$propertyList
callable$callback
Returns
void

Definition at line 310 of file PropPatch.php.

310 {
311
312 $argument = [];
313 foreach ($propertyList as $propertyName) {
314 $argument[$propertyName] = $this->mutations[$propertyName];
315 }
316
317 $result = $callback($argument);
318
319 if (is_array($result)) {
320 foreach ($propertyList as $propertyName) {
321 if (!isset($result[$propertyName])) {
322 $resultCode = 500;
323 } else {
324 $resultCode = $result[$propertyName];
325 }
326 if ($resultCode >= 400) {
327 $this->failed = true;
328 }
329 $this->result[$propertyName] = $resultCode;
330
331 }
332 } elseif ($result === true) {
333
334 // Success
335 foreach ($argument as $propertyName => $propertyValue) {
336 $this->result[$propertyName] = is_null($propertyValue) ? 204 : 200;
337 }
338
339 } elseif ($result === false) {
340 // Fail :(
341 $this->failed = true;
342 foreach ($propertyList as $propertyName) {
343 $this->result[$propertyName] = 403;
344 }
345 } else {
346 throw new UnexpectedValueException('A callback sent to handle() did not return an array or a bool');
347 }
348
349 }

References Sabre\DAV\PropPatch\$result.

◆ doCallBackSingleProp()

Sabre\DAV\PropPatch::doCallBackSingleProp (   $propertyName,
callable  $callback 
)
private

Executes a property callback with the single-property syntax.

Parameters
string$propertyName
callable$callback
Returns
void

Definition at line 276 of file PropPatch.php.

276 {
277
278 $result = $callback($this->mutations[$propertyName]);
279 if (is_bool($result)) {
280 if ($result) {
281 if (is_null($this->mutations[$propertyName])) {
282 // Delete
283 $result = 204;
284 } else {
285 // Update
286 $result = 200;
287 }
288 } else {
289 // Fail
290 $result = 403;
291 }
292 }
293 if (!is_int($result)) {
294 throw new UnexpectedValueException('A callback sent to handle() did not return an int or a bool');
295 }
296 $this->result[$propertyName] = $result;
297 if ($result >= 400) {
298 $this->failed = true;
299 }
300
301 }

References Sabre\DAV\PropPatch\$result.

◆ getMutations()

Sabre\DAV\PropPatch::getMutations ( )

Returns the full list of mutations.

Returns
array

Definition at line 367 of file PropPatch.php.

367 {
368
369 return $this->mutations;
370
371 }

References Sabre\DAV\PropPatch\$mutations.

Referenced by Sabre\DAV\TreeFileTester\propPatch(), and Sabre\DAV\CorePlugin\propPatchProtectedPropertyCheck().

+ Here is the caller graph for this function:

◆ getRemainingMutations()

Sabre\DAV\PropPatch::getRemainingMutations ( )

Returns the list of properties that don't have a result code yet.

This method returns a list of property names, but not its values.

Returns
string[]

Definition at line 184 of file PropPatch.php.

184 {
185
186 $remaining = [];
187 foreach ($this->mutations as $propertyName => $propValue) {
188 if (!isset($this->result[$propertyName])) {
189 $remaining[] = $propertyName;
190 }
191 }
192
193 return $remaining;
194
195 }
if($state['core:TerminatedAssocId'] !==null) $remaining

References $remaining.

Referenced by Sabre\DAV\Server\createCollection(), Sabre\DAV\PropPatch\handleRemaining(), and Sabre\DAV\PropPatch\setRemainingResultCode().

+ Here is the caller graph for this function:

◆ getRemainingValues()

Sabre\DAV\PropPatch::getRemainingValues ( )

Returns the list of properties that don't have a result code yet.

This method returns list of properties and their values.

Returns
array

Definition at line 204 of file PropPatch.php.

204 {
205
206 $remaining = [];
207 foreach ($this->mutations as $propertyName => $propValue) {
208 if (!isset($this->result[$propertyName])) {
209 $remaining[$propertyName] = $propValue;
210 }
211 }
212
213 return $remaining;
214
215 }

References $remaining.

Referenced by Sabre\CalDAV\CalendarHome\createExtendedCollection().

+ Here is the caller graph for this function:

◆ getResult()

Sabre\DAV\PropPatch::getResult ( )

Returns the result of the operation.

Returns
array

Definition at line 356 of file PropPatch.php.

356 {
357
358 return $this->result;
359
360 }

References Sabre\DAV\PropPatch\$result.

Referenced by Sabre\DAV\Server\createCollection().

+ Here is the caller graph for this function:

◆ handle()

Sabre\DAV\PropPatch::handle (   $properties,
callable  $callback 
)

Call this function if you wish to handle updating certain properties.

For instance, your class may be responsible for handling updates for the {DAV:}displayname property.

In that case, call this method with the first argument "{DAV:}displayname" and a second argument that's a method that does the actual updating.

It's possible to specify more than one property as an array.

The callback must return a boolean or an it. If the result is true, the operation was considered successful. If it's false, it's consided failed.

If the result is an integer, we'll use that integer as the http status code associated with the operation.

Parameters
string | string[]$properties
callable$callback
Returns
void

Definition at line 87 of file PropPatch.php.

87 {
88
89 $usedProperties = [];
90 foreach ((array)$properties as $propertyName) {
91
92 if (array_key_exists($propertyName, $this->mutations) && !isset($this->result[$propertyName])) {
93
94 $usedProperties[] = $propertyName;
95 // HTTP Accepted
96 $this->result[$propertyName] = 202;
97 }
98
99 }
100
101 // Only registering if there's any unhandled properties.
102 if (!$usedProperties) {
103 return;
104 }
105 $this->propertyUpdateCallbacks[] = [
106 // If the original argument to this method was a string, we need
107 // to also make sure that it stays that way, so the commit function
108 // knows how to format the arguments to the callback.
109 is_string($properties) ? $properties : $usedProperties,
110 $callback
111 ];
112
113 }

Referenced by Sabre\CalDAV\Schedule\Plugin\propPatch(), Sabre\DAV\HTTPPreferParsingTest\testproppatchMinimal(), and Sabre\DAV\ServerUpdatePropertiesTest\testUpdatePropertiesEventSuccess().

+ Here is the caller graph for this function:

◆ handleRemaining()

Sabre\DAV\PropPatch::handleRemaining ( callable  $callback)

Call this function if you wish to handle all properties that haven't been handled by anything else yet.

Note that you effectively claim with this that you promise to process all properties that are coming in.

Parameters
callable$callback
Returns
void

Definition at line 123 of file PropPatch.php.

123 {
124
125 $properties = $this->getRemainingMutations();
126 if (!$properties) {
127 // Nothing to do, don't register callback
128 return;
129 }
130
131 foreach ($properties as $propertyName) {
132 // HTTP Accepted
133 $this->result[$propertyName] = 202;
134
135 $this->propertyUpdateCallbacks[] = [
136 $properties,
137 $callback
138 ];
139 }
140
141 }
getRemainingMutations()
Returns the list of properties that don't have a result code yet.
Definition: PropPatch.php:184

References Sabre\DAV\PropPatch\getRemainingMutations().

Referenced by Sabre\DAV\PropertyStorage\Backend\PDO\propPatch(), Sabre\DAV\PropertyStorage\Backend\Mock\propPatch(), Sabre\DAV\Mock\PropertiesCollection\propPatch(), Sabre\DAV\ServerUpdatePropertiesTest\testUpdatePropertiesEventFail(), and Sabre\DAV\ServerUpdatePropertiesTest\testUpdatePropertiesProtected().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRemainingResultCode()

Sabre\DAV\PropPatch::setRemainingResultCode (   $resultCode)

Sets the result code for all properties that did not have a result yet.

Parameters
int$resultCode
Returns
void

Definition at line 168 of file PropPatch.php.

168 {
169
170 $this->setResultCode(
171 $this->getRemainingMutations(),
172 $resultCode
173 );
174
175 }
setResultCode($properties, $resultCode)
Sets the result code for one or more properties.
Definition: PropPatch.php:150

References Sabre\DAV\PropPatch\getRemainingMutations(), and Sabre\DAV\PropPatch\setResultCode().

Referenced by Sabre\CalDAV\CalendarHome\createExtendedCollection(), and Sabre\DAV\TreeFileTester\propPatch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setResultCode()

Sabre\DAV\PropPatch::setResultCode (   $properties,
  $resultCode 
)

Sets the result code for one or more properties.

Parameters
string | string[]$properties
int$resultCode
Returns
void

Definition at line 150 of file PropPatch.php.

150 {
151
152 foreach ((array)$properties as $propertyName) {
153 $this->result[$propertyName] = $resultCode;
154 }
155
156 if ($resultCode >= 400) {
157 $this->failed = true;
158 }
159
160 }

Referenced by Sabre\DAV\CorePlugin\propPatchProtectedPropertyCheck(), Sabre\DAV\PropPatch\setRemainingResultCode(), and Sabre\DAV\ServerUpdatePropertiesTest\testUpdatePropertiesEventFail().

+ Here is the caller graph for this function:

Field Documentation

◆ $failed

Sabre\DAV\PropPatch::$failed = false
protected

Definition at line 52 of file PropPatch.php.

Referenced by Sabre\DAV\PropPatch\commit().

◆ $mutations

Sabre\DAV\PropPatch::$mutations
protected

◆ $propertyUpdateCallbacks

Sabre\DAV\PropPatch::$propertyUpdateCallbacks = []
protected

Definition at line 45 of file PropPatch.php.

◆ $result

Sabre\DAV\PropPatch::$result = []
protected

The documentation for this class was generated from the following file: