From 580c3f4ffe9608d2beb56d418c68b3b112420e76 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Nov 2019 12:49:51 +0000 Subject: another bulk of composer updates (cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce) --- vendor/sabre/dav/lib/DAV/PartialUpdate/Plugin.php | 92 ++++++++++++----------- 1 file changed, 48 insertions(+), 44 deletions(-) (limited to 'vendor/sabre/dav/lib/DAV/PartialUpdate/Plugin.php') diff --git a/vendor/sabre/dav/lib/DAV/PartialUpdate/Plugin.php b/vendor/sabre/dav/lib/DAV/PartialUpdate/Plugin.php index 9c129d705..f8ffc3706 100644 --- a/vendor/sabre/dav/lib/DAV/PartialUpdate/Plugin.php +++ b/vendor/sabre/dav/lib/DAV/PartialUpdate/Plugin.php @@ -1,5 +1,7 @@ server = $server; $server->on('method:PATCH', [$this, 'httpPatch']); - } /** @@ -56,10 +56,9 @@ class Plugin extends DAV\ServerPlugin { * * @return string */ - function getPluginName() { - + public function getPluginName() + { return 'partialupdate'; - } /** @@ -74,10 +73,11 @@ class Plugin extends DAV\ServerPlugin { * - the node implements our partial update interface * * @param string $uri + * * @return array */ - function getHTTPMethods($uri) { - + public function getHTTPMethods($uri) + { $tree = $this->server->tree; if ($tree->nodeExists($uri)) { @@ -86,8 +86,8 @@ class Plugin extends DAV\ServerPlugin { return ['PATCH']; } } - return []; + return []; } /** @@ -95,25 +95,23 @@ class Plugin extends DAV\ServerPlugin { * * @return array */ - function getFeatures() { - + public function getFeatures() + { return ['sabredav-partialupdate']; - } /** - * Patch an uri + * Patch an uri. * * The WebDAV patch request can be used to modify only a part of an * existing resource. If the resource does not exist yet and the first * offset is not 0, the request fails * - * @param RequestInterface $request + * @param RequestInterface $request * @param ResponseInterface $response - * @return void */ - function httpPatch(RequestInterface $request, ResponseInterface $response) { - + public function httpPatch(RequestInterface $request, ResponseInterface $response) + { $path = $request->getPath(); // Get the node. Will throw a 404 if not found @@ -129,53 +127,55 @@ class Plugin extends DAV\ServerPlugin { } $contentType = strtolower( - $request->getHeader('Content-Type') + (string) $request->getHeader('Content-Type') ); - if ($contentType != 'application/x-sabredav-partialupdate') { - throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "' . $contentType . '"'); + if ('application/x-sabredav-partialupdate' != $contentType) { + throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "'.$contentType.'"'); } $len = $this->server->httpRequest->getHeader('Content-Length'); - if (!$len) throw new DAV\Exception\LengthRequired('A Content-Length header is required'); - + if (!$len) { + throw new DAV\Exception\LengthRequired('A Content-Length header is required'); + } switch ($range[0]) { - case self::RANGE_START : + case self::RANGE_START: // Calculate the end-range if it doesn't exist. if (!$range[2]) { $range[2] = $range[1] + $len - 1; } else { if ($range[2] < $range[1]) { - throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset (' . $range[2] . ') is lower than the start offset (' . $range[1] . ')'); + throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset ('.$range[2].') is lower than the start offset ('.$range[1].')'); } if ($range[2] - $range[1] + 1 != $len) { - throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length (' . $len . ') is not consistent with begin (' . $range[1] . ') and end (' . $range[2] . ') offsets'); + throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length ('.$len.') is not consistent with begin ('.$range[1].') and end ('.$range[2].') offsets'); } } break; } - if (!$this->server->emit('beforeWriteContent', [$path, $node, null])) + if (!$this->server->emit('beforeWriteContent', [$path, $node, null])) { return; + } $body = $this->server->httpRequest->getBody(); - $etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null); $this->server->emit('afterWriteContent', [$path, $node]); $response->setHeader('Content-Length', '0'); - if ($etag) $response->setHeader('ETag', $etag); + if ($etag) { + $response->setHeader('ETag', $etag); + } $response->setStatus(204); // Breaks the event chain return false; - } /** - * Returns the HTTP custom range update header + * Returns the HTTP custom range update header. * * This method returns null if there is no well-formed HTTP range request * header. It returns array(1) if it was an append request, array(2, @@ -192,24 +192,28 @@ class Plugin extends DAV\ServerPlugin { * [3,-5] - update from 5 bytes from the end of the file. * * @param RequestInterface $request + * * @return array|null */ - function getHTTPUpdateRange(RequestInterface $request) { - + public function getHTTPUpdateRange(RequestInterface $request) + { $range = $request->getHeader('X-Update-Range'); - if (is_null($range)) return null; + if (is_null($range)) { + return null; + } // Matching "Range: bytes=1234-5678: both numbers are optional - if (!preg_match('/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches)) return null; + if (!preg_match('/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches)) { + return null; + } - if ($matches[1] === 'append') { + if ('append' === $matches[1]) { return [self::RANGE_APPEND]; } elseif (strlen($matches[2]) > 0) { - return [self::RANGE_START, $matches[2], $matches[3] ?: null]; + return [self::RANGE_START, (int) $matches[2], (int) $matches[3] ?: null]; } else { - return [self::RANGE_END, $matches[4]]; + return [self::RANGE_END, (int) $matches[4]]; } - } } -- cgit v1.2.3