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

Partial update plugin (Patch method) More...

+ Inheritance diagram for Sabre\DAV\PartialUpdate\Plugin:
+ Collaboration diagram for Sabre\DAV\PartialUpdate\Plugin:

Public Member Functions

 initialize (DAV\Server $server)
 Initializes the plugin. More...
 
 getPluginName ()
 Returns a plugin name. More...
 
 getHTTPMethods ($uri)
 Use this method to tell the server this plugin defines additional HTTP methods. More...
 
 getFeatures ()
 Returns a list of features for the HTTP OPTIONS Dav: header. More...
 
 httpPatch (RequestInterface $request, ResponseInterface $response)
 Patch an uri. More...
 
 getHTTPUpdateRange (RequestInterface $request)
 Returns the HTTP custom range update header. More...
 
- Public Member Functions inherited from Sabre\DAV\ServerPlugin
 initialize (Server $server)
 This initializes the plugin. More...
 
 getFeatures ()
 This method should return a list of server-features. More...
 
 getHTTPMethods ($path)
 Use this method to tell the server this plugin defines additional HTTP methods. More...
 
 getPluginName ()
 Returns a plugin name. More...
 
 getSupportedReportSet ($uri)
 Returns a list of reports this plugin supports. More...
 
 getPluginInfo ()
 Returns a bunch of meta-data about the plugin. More...
 

Data Fields

const RANGE_APPEND = 1
 
const RANGE_START = 2
 
const RANGE_END = 3
 

Protected Attributes

 $server
 

Detailed Description

Partial update plugin (Patch method)

This plugin provides a way to modify only part of a target resource It may bu used to update a file chunk, upload big a file into smaller chunks or resume an upload.

$patchPlugin = new (); $server->addPlugin($patchPlugin);

Author
Jean-Tiare LE BIGOT (http://www.jtlebi.fr/) http://sabre.io/license/ Modified BSD License

Definition at line 23 of file Plugin.php.

Member Function Documentation

◆ getFeatures()

Sabre\DAV\PartialUpdate\Plugin::getFeatures ( )

Returns a list of features for the HTTP OPTIONS Dav: header.

Returns
array

Definition at line 98 of file Plugin.php.

98  {
99 
100  return ['sabredav-partialupdate'];
101 
102  }

◆ getHTTPMethods()

Sabre\DAV\PartialUpdate\Plugin::getHTTPMethods (   $uri)

Use this method to tell the server this plugin defines additional HTTP methods.

This method is passed a uri. It should only return HTTP methods that are available for the specified uri.

We claim to support PATCH method (partirl update) if and only if

  • the node exist
  • the node implements our partial update interface
Parameters
string$uri
Returns
array

Definition at line 79 of file Plugin.php.

References $tree.

79  {
80 
81  $tree = $this->server->tree;
82 
83  if ($tree->nodeExists($uri)) {
84  $node = $tree->getNodeForPath($uri);
85  if ($node instanceof IPatchSupport) {
86  return ['PATCH'];
87  }
88  }
89  return [];
90 
91  }

◆ getHTTPUpdateRange()

Sabre\DAV\PartialUpdate\Plugin::getHTTPUpdateRange ( RequestInterface  $request)

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, $start, $end) if it's a start and end range, lastly it's array(3, $endoffset) if the offset was negative, and should be calculated from the end of the file.

Examples:

null - invalid [1] - append [2,10,15] - update bytes 10, 11, 12, 13, 14, 15 [2,10,null] - update bytes 10 until the end of the patch body [3,-5] - update from 5 bytes from the end of the file.

Parameters
RequestInterface$request
Returns
array|null

Definition at line 197 of file Plugin.php.

References Sabre\HTTP\MessageInterface\getHeader().

Referenced by Sabre\DAV\PartialUpdate\Plugin\httpPatch().

197  {
198 
199  $range = $request->getHeader('X-Update-Range');
200  if (is_null($range)) return null;
201 
202  // Matching "Range: bytes=1234-5678: both numbers are optional
203 
204  if (!preg_match('/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches)) return null;
205 
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];
210  } else {
211  return [self::RANGE_END, $matches[4]];
212  }
213 
214  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPluginName()

Sabre\DAV\PartialUpdate\Plugin::getPluginName ( )

Returns a plugin name.

Using this name other plugins will be able to access other plugins using DAV::getPlugin

Returns
string

Definition at line 59 of file Plugin.php.

59  {
60 
61  return 'partialupdate';
62 
63  }

◆ httpPatch()

Sabre\DAV\PartialUpdate\Plugin::httpPatch ( RequestInterface  $request,
ResponseInterface  $response 
)

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

Parameters
RequestInterface$request
ResponseInterface$response
Returns
void

Definition at line 115 of file Plugin.php.

References $contentType, $path, Sabre\HTTP\MessageInterface\getHeader(), Sabre\DAV\PartialUpdate\Plugin\getHTTPUpdateRange(), Sabre\HTTP\RequestInterface\getPath(), Sabre\HTTP\MessageInterface\setHeader(), and Sabre\HTTP\ResponseInterface\setStatus().

115  {
116 
117  $path = $request->getPath();
118 
119  // Get the node. Will throw a 404 if not found
120  $node = $this->server->tree->getNodeForPath($path);
121  if (!$node instanceof IPatchSupport) {
122  throw new DAV\Exception\MethodNotAllowed('The target resource does not support the PATCH method.');
123  }
124 
125  $range = $this->getHTTPUpdateRange($request);
126 
127  if (!$range) {
128  throw new DAV\Exception\BadRequest('No valid "X-Update-Range" found in the headers');
129  }
130 
131  $contentType = strtolower(
132  $request->getHeader('Content-Type')
133  );
134 
135  if ($contentType != 'application/x-sabredav-partialupdate') {
136  throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "' . $contentType . '"');
137  }
138 
139  $len = $this->server->httpRequest->getHeader('Content-Length');
140  if (!$len) throw new DAV\Exception\LengthRequired('A Content-Length header is required');
141 
142  switch ($range[0]) {
143  case self::RANGE_START :
144  // Calculate the end-range if it doesn't exist.
145  if (!$range[2]) {
146  $range[2] = $range[1] + $len - 1;
147  } else {
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] . ')');
150  }
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');
153  }
154  }
155  break;
156  }
157 
158  if (!$this->server->emit('beforeWriteContent', [$path, $node, null]))
159  return;
160 
161  $body = $this->server->httpRequest->getBody();
162 
163 
164  $etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null);
165 
166  $this->server->emit('afterWriteContent', [$path, $node]);
167 
168  $response->setHeader('Content-Length', '0');
169  if ($etag) $response->setHeader('ETag', $etag);
170  $response->setStatus(204);
171 
172  // Breaks the event chain
173  return false;
174 
175  }
$path
Definition: aliased.php:25
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', mb_strtolower($path, 'UTF-8'))) $contentType
Definition: module.php:144
$response
getHTTPUpdateRange(RequestInterface $request)
Returns the HTTP custom range update header.
Definition: Plugin.php:197
+ Here is the call graph for this function:

◆ initialize()

Sabre\DAV\PartialUpdate\Plugin::initialize ( DAV\Server  $server)

Initializes the plugin.

This method is automatically called by the Server class after addPlugin.

Parameters
DAV\Server$server
Returns
void

Definition at line 44 of file Plugin.php.

References Sabre\DAV\PartialUpdate\Plugin\$server.

44  {
45 
46  $this->server = $server;
47  $server->on('method:PATCH', [$this, 'httpPatch']);
48 
49  }

Field Documentation

◆ $server

Sabre\DAV\PartialUpdate\Plugin::$server
protected

Definition at line 34 of file Plugin.php.

Referenced by Sabre\DAV\PartialUpdate\Plugin\initialize().

◆ RANGE_APPEND

const Sabre\DAV\PartialUpdate\Plugin::RANGE_APPEND = 1

Definition at line 25 of file Plugin.php.

◆ RANGE_END

const Sabre\DAV\PartialUpdate\Plugin::RANGE_END = 3

Definition at line 27 of file Plugin.php.

◆ RANGE_START

const Sabre\DAV\PartialUpdate\Plugin::RANGE_START = 2

Definition at line 26 of file Plugin.php.


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