47 $server->on(
'method:PATCH', [$this,
'httpPatch']);
61 return 'partialupdate';
81 $tree = $this->server->tree;
83 if (
$tree->nodeExists($uri)) {
84 $node =
$tree->getNodeForPath($uri);
100 return [
'sabredav-partialupdate'];
120 $node = $this->server->tree->getNodeForPath(
$path);
122 throw new DAV\Exception\MethodNotAllowed(
'The target resource does not support the PATCH method.');
128 throw new DAV\Exception\BadRequest(
'No valid "X-Update-Range" found in the headers');
135 if (
$contentType !=
'application/x-sabredav-partialupdate') {
136 throw new DAV\Exception\UnsupportedMediaType(
'Unknown Content-Type header "' .
$contentType .
'"');
139 $len = $this->server->httpRequest->getHeader(
'Content-Length');
140 if (!$len)
throw new DAV\Exception\LengthRequired(
'A Content-Length header is required');
143 case self::RANGE_START :
146 $range[2] = $range[1] + $len - 1;
148 if ($range[2] < $range[1]) {
149 throw new DAV\Exception\RequestedRangeNotSatisfiable(
'The end offset (' . $range[2] .
') is lower than the start offset (' . $range[1] .
')');
151 if ($range[2] - $range[1] + 1 != $len) {
152 throw new DAV\Exception\RequestedRangeNotSatisfiable(
'Actual data length (' . $len .
') is not consistent with begin (' . $range[1] .
') and end (' . $range[2] .
') offsets');
158 if (!$this->server->emit(
'beforeWriteContent', [
$path, $node, null]))
161 $body = $this->server->httpRequest->getBody();
164 $etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null);
166 $this->server->emit(
'afterWriteContent', [
$path, $node]);
168 $response->
setHeader(
'Content-Length',
'0');
169 if ($etag) $response->
setHeader(
'ETag', $etag);
199 $range = $request->
getHeader(
'X-Update-Range');
200 if (is_null($range))
return null;
204 if (!preg_match(
'/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches))
return null;
206 if ($matches[1] ===
'append') {
207 return [self::RANGE_APPEND];
208 } elseif (strlen($matches[2]) > 0) {
209 return [self::RANGE_START, $matches[2], $matches[3] ?: null];
211 return [self::RANGE_END, $matches[4]];
This interface represents a HTTP response.
The RequestInterface represents a HTTP request.
This interface provides a way to modify only part of a target resource It may be used to update a fil...
The baseclass for all server plugins.
getFeatures()
Returns a list of features for the HTTP OPTIONS Dav: header.
httpPatch(RequestInterface $request, ResponseInterface $response)
Patch an uri.
foreach($paths as $path) $request
initialize(DAV\Server $server)
Initializes the plugin.
Partial update plugin (Patch method)
getHTTPMethods($uri)
Use this method to tell the server this plugin defines additional HTTP methods.
setStatus($status)
Sets the HTTP status code.
getHeader($name)
Returns a specific HTTP header, based on it's name.
getPath()
Returns the relative path.
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', mb_strtolower($path, 'UTF-8'))) $contentType
getPluginName()
Returns a plugin name.
getHTTPUpdateRange(RequestInterface $request)
Returns the HTTP custom range update header.
setHeader($name, $value)
Updates a HTTP header.