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

SabreDAV DAV client. More...

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

Public Member Functions

 __construct (array $settings)
 Constructor. More...
 
 propFind ($url, array $properties, $depth=0)
 Does a PROPFIND request. More...
 
 propPatch ($url, array $properties)
 Updates a list of properties on the server. More...
 
 options ()
 Performs an HTTP options request. More...
 
 request ($method, $url='', $body=null, array $headers=[])
 Performs an actual HTTP request, and returns the result. More...
 
 getAbsoluteUrl ($url)
 Returns the full url based on the given url (which may be relative). More...
 
 parseMultiStatus ($body)
 Parses a WebDAV multistatus response body. More...
 
- Public Member Functions inherited from Sabre\HTTP\Client
 __construct ()
 Initializes the client. More...
 
 send (RequestInterface $request)
 Sends a request to a HTTP server, and returns a response. More...
 
 sendAsync (RequestInterface $request, callable $success=null, callable $error=null)
 Sends a HTTP request asynchronously. More...
 
 poll ()
 This method checks if any http requests have gotten results, and if so, call the appropriate success or error handlers. More...
 
 wait ()
 Processes every HTTP request in the queue, and waits till they are all completed. More...
 
 setThrowExceptions ($throwExceptions)
 If this is set to true, the Client will automatically throw exceptions upon HTTP errors. More...
 
 addCurlSetting ($name, $value)
 Adds a CURL setting. More...
 
- Public Member Functions inherited from Sabre\Event\EventEmitterInterface
 on ($eventName, callable $callBack, $priority=100)
 Subscribe to an event. More...
 
 once ($eventName, callable $callBack, $priority=100)
 Subscribe to an event exactly once. More...
 
 emit ($eventName, array $arguments=[], callable $continueCallBack=null)
 Emits an event. More...
 
 listeners ($eventName)
 Returns the list of listeners for an event. More...
 
 removeListener ($eventName, callable $listener)
 Removes a specific listener from an event. More...
 
 removeAllListeners ($eventName=null)
 Removes all listeners. More...
 

Data Fields

 $xml
 
 $propertyMap = []
 
const AUTH_BASIC = 1
 Basic authentication. More...
 
const AUTH_DIGEST = 2
 Digest authentication. More...
 
const AUTH_NTLM = 4
 NTLM authentication. More...
 
const ENCODING_IDENTITY = 1
 Identity encoding, which basically does not nothing. More...
 
const ENCODING_DEFLATE = 2
 Deflate encoding. More...
 
const ENCODING_GZIP = 4
 Gzip encoding. More...
 
const ENCODING_ALL = 7
 Sends all encoding headers. More...
 
- Data Fields inherited from Sabre\HTTP\Client
const STATUS_SUCCESS = 0
 
const STATUS_CURLERROR = 1
 
const STATUS_HTTPERROR = 2
 

Protected Attributes

 $baseUri
 
 $encoding = self::ENCODING_IDENTITY
 
- Protected Attributes inherited from Sabre\HTTP\Client
 $curlSettings = []
 
 $throwExceptions = false
 
 $maxRedirects = 5
 

Additional Inherited Members

- Protected Member Functions inherited from Sabre\HTTP\Client
 doRequest (RequestInterface $request)
 This method is responsible for performing a single request. More...
 
 createCurlSettingsArray (RequestInterface $request)
 Turns a RequestInterface object into an array with settings that can be fed to curl_setopt. More...
 
 parseCurlResult ($response, $curlHandle)
 Parses the result of a curl call in a format that's a bit more convenient to work with. More...
 
 sendAsyncInternal (RequestInterface $request, callable $success, callable $error, $retryCount=0)
 Sends an asynchronous HTTP request. More...
 
 curlExec ($curlHandle)
 Calls curl_exec. More...
 
 curlStuff ($curlHandle)
 Returns a bunch of information about a curl request. More...
 

Detailed Description

SabreDAV DAV client.

This client wraps around Curl to provide a convenient API to a WebDAV server.

NOTE: This class is experimental, it's api will likely change in the future.

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

Definition at line 20 of file Client.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\DAV\Client::__construct ( array  $settings)

Constructor.

Settings are provided through the 'settings' argument. The following settings are supported:

  • baseUri
  • userName (optional)
  • password (optional)
  • proxy (optional)
  • authType (optional)
  • encoding (optional)

authType must be a bitmap, using self::AUTH_BASIC, self::AUTH_DIGEST and self::AUTH_NTLM. If you know which authentication method will be used, it's recommended to set it, as it will save a great deal of requests to 'discover' this information.

Encoding is a bitmap with one of the ENCODING constants.

Parameters
array$settings

Definition at line 115 of file Client.php.

References Sabre\DAV\Client\$encoding, $password, Sabre\HTTP\Client\addCurlSetting(), and Sabre\DAV\Version\VERSION.

115  {
116 
117  if (!isset($settings['baseUri'])) {
118  throw new \InvalidArgumentException('A baseUri must be provided');
119  }
120 
121  parent::__construct();
122 
123  $this->baseUri = $settings['baseUri'];
124 
125  if (isset($settings['proxy'])) {
126  $this->addCurlSetting(CURLOPT_PROXY, $settings['proxy']);
127  }
128 
129  if (isset($settings['userName'])) {
130  $userName = $settings['userName'];
131  $password = isset($settings['password']) ? $settings['password'] : '';
132 
133  if (isset($settings['authType'])) {
134  $curlType = 0;
135  if ($settings['authType'] & self::AUTH_BASIC) {
136  $curlType |= CURLAUTH_BASIC;
137  }
138  if ($settings['authType'] & self::AUTH_DIGEST) {
139  $curlType |= CURLAUTH_DIGEST;
140  }
141  if ($settings['authType'] & self::AUTH_NTLM) {
142  $curlType |= CURLAUTH_NTLM;
143  }
144  } else {
145  $curlType = CURLAUTH_BASIC | CURLAUTH_DIGEST;
146  }
147 
148  $this->addCurlSetting(CURLOPT_HTTPAUTH, $curlType);
149  $this->addCurlSetting(CURLOPT_USERPWD, $userName . ':' . $password);
150 
151  }
152 
153  if (isset($settings['encoding'])) {
154  $encoding = $settings['encoding'];
155 
156  $encodings = [];
157  if ($encoding & self::ENCODING_IDENTITY) {
158  $encodings[] = 'identity';
159  }
160  if ($encoding & self::ENCODING_DEFLATE) {
161  $encodings[] = 'deflate';
162  }
163  if ($encoding & self::ENCODING_GZIP) {
164  $encodings[] = 'gzip';
165  }
166  $this->addCurlSetting(CURLOPT_ENCODING, implode(',', $encodings));
167  }
168 
169  $this->addCurlSetting(CURLOPT_USERAGENT, 'sabre-dav/' . Version::VERSION . ' (http://sabre.io/)');
170 
171  $this->xml = new Xml\Service();
172  // BC
173  $this->propertyMap = & $this->xml->elementMap;
174 
175  }
const VERSION
Full version number.
Definition: Version.php:17
$password
Definition: cron.php:14
addCurlSetting($name, $value)
Adds a CURL setting.
Definition: Client.php:331
+ Here is the call graph for this function:

Member Function Documentation

◆ getAbsoluteUrl()

Sabre\DAV\Client::getAbsoluteUrl (   $url)

Returns the full url based on the given url (which may be relative).

All urls are expanded based on the base url as given by the server.

Parameters
string$url
Returns
string

Definition at line 389 of file Client.php.

References $url, and Sabre\Uri\resolve().

Referenced by Sabre\DAV\Client\options(), Sabre\DAV\Client\propFind(), Sabre\DAV\Client\propPatch(), and Sabre\DAV\Client\request().

389  {
390 
391  return Uri\resolve(
392  $this->baseUri,
393  $url
394  );
395 
396  }
resolve($basePath, $newPath)
This file contains all the uri handling functions.
Definition: functions.php:23
$url
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ options()

Sabre\DAV\Client::options ( )

Performs an HTTP options request.

This method returns all the features from the 'DAV:' header as an array. If there was no DAV header, or no contents this method will return an empty array.

Returns
array

Definition at line 322 of file Client.php.

References $request, $response, Sabre\DAV\Client\getAbsoluteUrl(), and Sabre\HTTP\Client\send().

322  {
323 
324  $request = new HTTP\Request('OPTIONS', $this->getAbsoluteUrl(''));
325  $response = $this->send($request);
326 
327  $dav = $response->getHeader('Dav');
328  if (!$dav) {
329  return [];
330  }
331 
332  $features = explode(',', $dav);
333  foreach ($features as &$v) {
334  $v = trim($v);
335  }
336  return $features;
337 
338  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
send(RequestInterface $request)
Sends a request to a HTTP server, and returns a response.
Definition: Client.php:89
getAbsoluteUrl($url)
Returns the full url based on the given url (which may be relative).
Definition: Client.php:389
$response
+ Here is the call graph for this function:

◆ parseMultiStatus()

Sabre\DAV\Client::parseMultiStatus (   $body)

Parses a WebDAV multistatus response body.

This method returns an array with the following structure

[ 'url/to/resource' => [ '200' => [ '{DAV:}property1' => 'value1', '{DAV:}property2' => 'value2', ], '404' => [ '{DAV:}property1' => null, '{DAV:}property2' => null, ], ], 'url/to/resource2' => [ .. etc .. ] ]

Parameters
string$bodyxml body
Returns
array

Definition at line 423 of file Client.php.

References $response, and $result.

Referenced by Sabre\DAV\Client\propFind(), and Sabre\DAV\Client\propPatch().

423  {
424 
425  $multistatus = $this->xml->expect('{DAV:}multistatus', $body);
426 
427  $result = [];
428 
429  foreach ($multistatus->getResponses() as $response) {
430 
431  $result[$response->getHref()] = $response->getResponseProperties();
432 
433  }
434 
435  return $result;
436 
437  }
$result
$response
+ Here is the caller graph for this function:

◆ propFind()

Sabre\DAV\Client::propFind (   $url,
array  $properties,
  $depth = 0 
)

Does a PROPFIND request.

The list of requested properties must be specified as an array, in clark notation.

The returned array will contain a list of filenames as keys, and properties as values.

The properties array will contain the list of properties. Only properties that are actually returned from the server (without error) will be returned, anything else is discarded.

Depth should be either 0 or 1. A depth of 1 will cause a request to be made to the server to also return all child resources.

Parameters
string$url
array$properties
int$depth
Returns
array

Definition at line 198 of file Client.php.

References $namespace, $request, $response, $result, $root, $url, Sabre\DAV\Client\getAbsoluteUrl(), Sabre\Xml\Service\parseClarkNotation(), Sabre\DAV\Client\parseMultiStatus(), and Sabre\HTTP\Client\send().

198  {
199 
200  $dom = new \DOMDocument('1.0', 'UTF-8');
201  $dom->formatOutput = true;
202  $root = $dom->createElementNS('DAV:', 'd:propfind');
203  $prop = $dom->createElement('d:prop');
204 
205  foreach ($properties as $property) {
206 
207  list(
208  $namespace,
209  $elementName
211 
212  if ($namespace === 'DAV:') {
213  $element = $dom->createElement('d:' . $elementName);
214  } else {
215  $element = $dom->createElementNS($namespace, 'x:' . $elementName);
216  }
217 
218  $prop->appendChild($element);
219  }
220 
221  $dom->appendChild($root)->appendChild($prop);
222  $body = $dom->saveXML();
223 
224  $url = $this->getAbsoluteUrl($url);
225 
226  $request = new HTTP\Request('PROPFIND', $url, [
227  'Depth' => $depth,
228  'Content-Type' => 'application/xml'
229  ], $body);
230 
231  $response = $this->send($request);
232 
233  if ((int)$response->getStatus() >= 400) {
234  throw new HTTP\ClientHttpException($response);
235  }
236 
237  $result = $this->parseMultiStatus($response->getBodyAsString());
238 
239  // If depth was 0, we only return the top item
240  if ($depth === 0) {
241  reset($result);
242  $result = current($result);
243  return isset($result[200]) ? $result[200] : [];
244  }
245 
246  $newResult = [];
247  foreach ($result as $href => $statusList) {
248 
249  $newResult[$href] = isset($statusList[200]) ? $statusList[200] : [];
250 
251  }
252 
253  return $newResult;
254 
255  }
if($err=$client->getError()) $namespace
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
send(RequestInterface $request)
Sends a request to a HTTP server, and returns a response.
Definition: Client.php:89
getAbsoluteUrl($url)
Returns the full url based on the given url (which may be relative).
Definition: Client.php:389
parseMultiStatus($body)
Parses a WebDAV multistatus response body.
Definition: Client.php:423
static parseClarkNotation($str)
Parses a clark-notation string, and returns the namespace and element name components.
Definition: Service.php:274
$root
Definition: sabredav.php:45
$url
$response
+ Here is the call graph for this function:

◆ propPatch()

Sabre\DAV\Client::propPatch (   $url,
array  $properties 
)

Updates a list of properties on the server.

The list of properties must have clark-notation properties for the keys, and the actual (string) value for the value. If the value is null, an attempt is made to delete the property.

Parameters
string$url
array$properties
Returns
bool

Definition at line 268 of file Client.php.

References $request, $response, $result, $url, Sabre\DAV\Client\$xml, Sabre\DAV\Client\getAbsoluteUrl(), Sabre\DAV\Client\parseMultiStatus(), and Sabre\HTTP\Client\send().

268  {
269 
270  $propPatch = new Xml\Request\PropPatch();
271  $propPatch->properties = $properties;
272  $xml = $this->xml->write(
273  '{DAV:}propertyupdate',
274  $propPatch
275  );
276 
277  $url = $this->getAbsoluteUrl($url);
278  $request = new HTTP\Request('PROPPATCH', $url, [
279  'Content-Type' => 'application/xml',
280  ], $xml);
281  $response = $this->send($request);
282 
283  if ($response->getStatus() >= 400) {
284  throw new HTTP\ClientHttpException($response);
285  }
286 
287  if ($response->getStatus() === 207) {
288  // If it's a 207, the request could still have failed, but the
289  // information is hidden in the response body.
290  $result = $this->parseMultiStatus($response->getBodyAsString());
291 
292  $errorProperties = [];
293  foreach ($result as $href => $statusList) {
294  foreach ($statusList as $status => $properties) {
295 
296  if ($status >= 400) {
297  foreach ($properties as $propName => $propValue) {
298  $errorProperties[] = $propName . ' (' . $status . ')';
299  }
300  }
301 
302  }
303  }
304  if ($errorProperties) {
305 
306  throw new HTTP\ClientException('PROPPATCH failed. The following properties errored: ' . implode(', ', $errorProperties));
307  }
308  }
309  return true;
310 
311  }
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
send(RequestInterface $request)
Sends a request to a HTTP server, and returns a response.
Definition: Client.php:89
getAbsoluteUrl($url)
Returns the full url based on the given url (which may be relative).
Definition: Client.php:389
parseMultiStatus($body)
Parses a WebDAV multistatus response body.
Definition: Client.php:423
$url
$response
+ Here is the call graph for this function:

◆ request()

Sabre\DAV\Client::request (   $method,
  $url = '',
  $body = null,
array  $headers = [] 
)

Performs an actual HTTP request, and returns the result.

If the specified url is relative, it will be expanded based on the base url.

The returned array contains 3 keys:

  • body - the response body
  • httpCode - a HTTP code (200, 404, etc)
  • headers - a list of response http headers. The header names have been lowercased.

For large uploads, it's highly recommended to specify body as a stream resource. You can easily do this by simply passing the result of fopen(..., 'r').

This method will throw an exception if an HTTP error was received. Any HTTP status code above 399 is considered an error.

Note that it is no longer recommended to use this method, use the send() method instead.

Parameters
string$method
string$url
string | resource | null$body
array$headers
Exceptions
ClientException,incase a curl error occurred.
Returns
array

Definition at line 369 of file Client.php.

References $response, $url, Sabre\DAV\Client\getAbsoluteUrl(), and Sabre\HTTP\Client\send().

Referenced by Sabre\DAV\ClientMock\doRequest().

369  {
370 
371  $url = $this->getAbsoluteUrl($url);
372 
373  $response = $this->send(new HTTP\Request($method, $url, $headers, $body));
374  return [
375  'body' => $response->getBodyAsString(),
376  'statusCode' => (int)$response->getStatus(),
377  'headers' => array_change_key_case($response->getHeaders()),
378  ];
379 
380  }
send(RequestInterface $request)
Sends a request to a HTTP server, and returns a response.
Definition: Client.php:89
getAbsoluteUrl($url)
Returns the full url based on the given url (which may be relative).
Definition: Client.php:389
$url
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $baseUri

Sabre\DAV\Client::$baseUri
protected

Definition at line 49 of file Client.php.

◆ $encoding

Sabre\DAV\Client::$encoding = self::ENCODING_IDENTITY
protected

Definition at line 91 of file Client.php.

Referenced by Sabre\DAV\Client\__construct().

◆ $propertyMap

Sabre\DAV\Client::$propertyMap = []

Definition at line 40 of file Client.php.

◆ $xml

Sabre\DAV\Client::$xml

Definition at line 29 of file Client.php.

Referenced by Sabre\DAV\Client\propPatch().

◆ AUTH_BASIC

const Sabre\DAV\Client::AUTH_BASIC = 1

Basic authentication.

Definition at line 54 of file Client.php.

Referenced by Sabre\DAV\ClientTest\testBasicAuth().

◆ AUTH_DIGEST

const Sabre\DAV\Client::AUTH_DIGEST = 2

Digest authentication.

Definition at line 59 of file Client.php.

Referenced by Sabre\DAV\ClientTest\testDigestAuth().

◆ AUTH_NTLM

const Sabre\DAV\Client::AUTH_NTLM = 4

NTLM authentication.

Definition at line 64 of file Client.php.

Referenced by Sabre\DAV\ClientTest\testNTLMAuth().

◆ ENCODING_ALL

const Sabre\DAV\Client::ENCODING_ALL = 7

Sends all encoding headers.

Definition at line 84 of file Client.php.

◆ ENCODING_DEFLATE

const Sabre\DAV\Client::ENCODING_DEFLATE = 2

Deflate encoding.

Definition at line 74 of file Client.php.

Referenced by Sabre\DAV\ClientTest\testEncoding().

◆ ENCODING_GZIP

const Sabre\DAV\Client::ENCODING_GZIP = 4

Gzip encoding.

Definition at line 79 of file Client.php.

Referenced by Sabre\DAV\ClientTest\testEncoding().

◆ ENCODING_IDENTITY

const Sabre\DAV\Client::ENCODING_IDENTITY = 1

Identity encoding, which basically does not nothing.

Definition at line 69 of file Client.php.

Referenced by Sabre\DAV\ClientTest\testEncoding().


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