diff options
author | Mario <mario@mariovavti.com> | 2019-12-04 10:25:11 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2019-12-04 10:25:11 +0000 |
commit | bde429cff649237984903a252ba1a718e6d74f53 (patch) | |
tree | b2b2570159cfb37689e6ce3b96c3b1b988d676cc /vendor/sabre/dav/lib/DAV/PropPatch.php | |
parent | cc9f41df5f83bcab435d6fb941b5a8f5b1457037 (diff) | |
parent | 4c8d33d1eb2a804aa70a7bc677d6c73d0d94816b (diff) | |
download | volse-hubzilla-4.6.tar.gz volse-hubzilla-4.6.tar.bz2 volse-hubzilla-4.6.zip |
Merge branch '4.6RC'4.6
Diffstat (limited to 'vendor/sabre/dav/lib/DAV/PropPatch.php')
-rw-r--r-- | vendor/sabre/dav/lib/DAV/PropPatch.php | 113 |
1 files changed, 42 insertions, 71 deletions
diff --git a/vendor/sabre/dav/lib/DAV/PropPatch.php b/vendor/sabre/dav/lib/DAV/PropPatch.php index 6d599dacc..160bdb1a8 100644 --- a/vendor/sabre/dav/lib/DAV/PropPatch.php +++ b/vendor/sabre/dav/lib/DAV/PropPatch.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV; use UnexpectedValueException; @@ -17,8 +19,8 @@ use UnexpectedValueException; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class PropPatch { - +class PropPatch +{ /** * Properties that are being updated. * @@ -52,14 +54,13 @@ class PropPatch { protected $failed = false; /** - * Constructor + * Constructor. * * @param array $mutations A list of updates */ - function __construct(array $mutations) { - + public function __construct(array $mutations) + { $this->mutations = $mutations; - } /** @@ -81,21 +82,17 @@ class PropPatch { * code associated with the operation. * * @param string|string[] $properties - * @param callable $callback - * @return void + * @param callable $callback */ - function handle($properties, callable $callback) { - + public function handle($properties, callable $callback) + { $usedProperties = []; - foreach ((array)$properties as $propertyName) { - + foreach ((array) $properties as $propertyName) { if (array_key_exists($propertyName, $this->mutations) && !isset($this->result[$propertyName])) { - $usedProperties[] = $propertyName; // HTTP Accepted $this->result[$propertyName] = 202; } - } // Only registering if there's any unhandled properties. @@ -107,9 +104,8 @@ class PropPatch { // to also make sure that it stays that way, so the commit function // knows how to format the arguments to the callback. is_string($properties) ? $properties : $usedProperties, - $callback + $callback, ]; - } /** @@ -118,10 +114,9 @@ class PropPatch { * this that you promise to process _all_ properties that are coming in. * * @param callable $callback - * @return void */ - function handleRemaining(callable $callback) { - + public function handleRemaining(callable $callback) + { $properties = $this->getRemainingMutations(); if (!$properties) { // Nothing to do, don't register callback @@ -134,44 +129,39 @@ class PropPatch { $this->propertyUpdateCallbacks[] = [ $properties, - $callback + $callback, ]; } - } /** * Sets the result code for one or more properties. * * @param string|string[] $properties - * @param int $resultCode - * @return void + * @param int $resultCode */ - function setResultCode($properties, $resultCode) { - - foreach ((array)$properties as $propertyName) { + public function setResultCode($properties, $resultCode) + { + foreach ((array) $properties as $propertyName) { $this->result[$propertyName] = $resultCode; } if ($resultCode >= 400) { $this->failed = true; } - } /** * Sets the result code for all properties that did not have a result yet. * * @param int $resultCode - * @return void */ - function setRemainingResultCode($resultCode) { - + public function setRemainingResultCode($resultCode) + { $this->setResultCode( $this->getRemainingMutations(), $resultCode ); - } /** @@ -181,8 +171,8 @@ class PropPatch { * * @return string[] */ - function getRemainingMutations() { - + public function getRemainingMutations() + { $remaining = []; foreach ($this->mutations as $propertyName => $propValue) { if (!isset($this->result[$propertyName])) { @@ -191,7 +181,6 @@ class PropPatch { } return $remaining; - } /** @@ -201,8 +190,8 @@ class PropPatch { * * @return array */ - function getRemainingValues() { - + public function getRemainingValues() + { $remaining = []; foreach ($this->mutations as $propertyName => $propValue) { if (!isset($this->result[$propertyName])) { @@ -211,7 +200,6 @@ class PropPatch { } return $remaining; - } /** @@ -222,20 +210,17 @@ class PropPatch { * * @return bool */ - function commit() { - + public function commit() + { // First we validate if every property has a handler foreach ($this->mutations as $propertyName => $value) { - if (!isset($this->result[$propertyName])) { $this->failed = true; $this->result[$propertyName] = 403; } - } foreach ($this->propertyUpdateCallbacks as $callbackInfo) { - if ($this->failed) { break; } @@ -244,37 +229,32 @@ class PropPatch { } else { $this->doCallbackMultiProp($callbackInfo[0], $callbackInfo[1]); } - } - /** + /* * If anywhere in this operation updating a property failed, we must * update all other properties accordingly. */ if ($this->failed) { - foreach ($this->result as $propertyName => $status) { - if ($status === 202) { + if (202 === $status) { // Failed dependency $this->result[$propertyName] = 424; } } - } return !$this->failed; - } /** * Executes a property callback with the single-property syntax. * - * @param string $propertyName + * @param string $propertyName * @param callable $callback - * @return void */ - private function doCallBackSingleProp($propertyName, callable $callback) { - + private function doCallBackSingleProp($propertyName, callable $callback) + { $result = $callback($this->mutations[$propertyName]); if (is_bool($result)) { if ($result) { @@ -297,18 +277,16 @@ class PropPatch { if ($result >= 400) { $this->failed = true; } - } /** * Executes a property callback with the multi-property syntax. * - * @param array $propertyList + * @param array $propertyList * @param callable $callback - * @return void */ - private function doCallBackMultiProp(array $propertyList, callable $callback) { - + private function doCallBackMultiProp(array $propertyList, callable $callback) + { $argument = []; foreach ($propertyList as $propertyName) { $argument[$propertyName] = $this->mutations[$propertyName]; @@ -327,16 +305,13 @@ class PropPatch { $this->failed = true; } $this->result[$propertyName] = $resultCode; - } - } elseif ($result === true) { - + } elseif (true === $result) { // Success foreach ($argument as $propertyName => $propertyValue) { $this->result[$propertyName] = is_null($propertyValue) ? 204 : 200; } - - } elseif ($result === false) { + } elseif (false === $result) { // Fail :( $this->failed = true; foreach ($propertyList as $propertyName) { @@ -345,7 +320,6 @@ class PropPatch { } else { throw new UnexpectedValueException('A callback sent to handle() did not return an array or a bool'); } - } /** @@ -353,21 +327,18 @@ class PropPatch { * * @return array */ - function getResult() { - + public function getResult() + { return $this->result; - } /** - * Returns the full list of mutations + * Returns the full list of mutations. * * @return array */ - function getMutations() { - + public function getMutations() + { return $this->mutations; - } - } |