Client
extends Client
in package
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.
Tags
Table of Contents
- AUTH_BASIC = 1
- Basic authentication.
- AUTH_DIGEST = 2
- Digest authentication.
- AUTH_NTLM = 4
- NTLM authentication.
- ENCODING_ALL = 7
- Sends all encoding headers.
- ENCODING_DEFLATE = 2
- Deflate encoding.
- ENCODING_GZIP = 4
- Gzip encoding.
- ENCODING_IDENTITY = 1
- Identity encoding, which basically does not nothing.
- STATUS_CURLERROR = 1
- STATUS_HTTPERROR = 2
- STATUS_SUCCESS = 0
- $propertyMap : array<string|int, mixed>
- The elementMap.
- $xml : mixed
- The xml service.
- $baseUri : string
- Base URI.
- $curlSettings : array<string|int, mixed>
- List of curl settings.
- $encoding : int
- Content-encoding.
- $headerLinesMap : mixed
- $listeners : array<string|int, mixed>
- The list of listeners.
- $maxRedirects : int
- The maximum number of times we'll follow a redirect.
- $throwExceptions : bool
- Wether or not exceptions should be thrown when a HTTP error is returned.
- $curlHandle : resource
- Cached curl handle.
- $curlMultiHandle : resource
- Handler for curl_multi requests.
- $curlMultiMap : array<string|int, mixed>
- Has a list of curl handles, as well as their associated success and error callbacks.
- __construct() : mixed
- Constructor.
- addCurlSetting() : mixed
- Adds a CURL setting.
- emit() : bool
- Emits an event.
- getAbsoluteUrl() : string
- 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.
- listeners() : array<string|int, callable>
- Returns the list of listeners for an event.
- on() : mixed
- Subscribe to an event.
- once() : mixed
- Subscribe to an event exactly once.
- options() : array<string|int, mixed>
- Performs an HTTP options request.
- parseMultiStatus() : array<string|int, mixed>
- Parses a WebDAV multistatus response body.
- poll() : bool
- This method checks if any http requests have gotten results, and if so, call the appropriate success or error handlers.
- propFind() : array<string|int, mixed>
- Does a PROPFIND request.
- propPatch() : bool
- Updates a list of properties on the server.
- removeAllListeners() : mixed
- Removes all listeners.
- removeListener() : bool
- Removes a specific listener from an event.
- request() : array<string|int, mixed>
- Performs an actual HTTP request, and returns the result.
- send() : ResponseInterface
- Sends a request to a HTTP server, and returns a response.
- sendAsync() : mixed
- Sends a HTTP request asynchronously.
- setThrowExceptions() : mixed
- If this is set to true, the Client will automatically throw exceptions upon HTTP errors.
- wait() : mixed
- Processes every HTTP request in the queue, and waits till they are all completed.
- createCurlSettingsArray() : array<string|int, mixed>
- Turns a RequestInterface object into an array with settings that can be fed to curl_setopt.
- curlExec() : string
- Calls curl_exec.
- curlStuff() : array<string|int, mixed>
- Returns a bunch of information about a curl request.
- doRequest() : ResponseInterface
- This method is responsible for performing a single request.
- parseCurlResponse() : array<string|int, mixed>
- Parses the result of a curl call in a format that's a bit more convenient to work with.
- parseCurlResult() : array<string|int, mixed>
- Parses the result of a curl call in a format that's a bit more convenient to work with.
- receiveCurlHeader() : mixed
- sendAsyncInternal() : mixed
- Sends an asynchronous HTTP request.
- parseResponse() : array<string|int, mixed>
Constants
AUTH_BASIC
Basic authentication.
public
mixed
AUTH_BASIC
= 1
AUTH_DIGEST
Digest authentication.
public
mixed
AUTH_DIGEST
= 2
AUTH_NTLM
NTLM authentication.
public
mixed
AUTH_NTLM
= 4
ENCODING_ALL
Sends all encoding headers.
public
mixed
ENCODING_ALL
= 7
ENCODING_DEFLATE
Deflate encoding.
public
mixed
ENCODING_DEFLATE
= 2
ENCODING_GZIP
Gzip encoding.
public
mixed
ENCODING_GZIP
= 4
ENCODING_IDENTITY
Identity encoding, which basically does not nothing.
public
mixed
ENCODING_IDENTITY
= 1
STATUS_CURLERROR
public
mixed
STATUS_CURLERROR
= 1
STATUS_HTTPERROR
public
mixed
STATUS_HTTPERROR
= 2
STATUS_SUCCESS
public
mixed
STATUS_SUCCESS
= 0
Properties
$propertyMap
The elementMap.
public
array<string|int, mixed>
$propertyMap
= []
This property is linked via reference to $this->xml->elementMap. It's deprecated as of version 3.0.0, and should no longer be used.
Tags
$xml
The xml service.
public
mixed
$xml
Uset this service to configure the property and namespace maps.
$baseUri
Base URI.
protected
string
$baseUri
This URI will be used to resolve relative urls.
$curlSettings
List of curl settings.
protected
array<string|int, mixed>
$curlSettings
= []
$encoding
Content-encoding.
protected
int
$encoding
= self::ENCODING_IDENTITY
$headerLinesMap
protected
mixed
$headerLinesMap
= []
$listeners
The list of listeners.
protected
array<string|int, mixed>
$listeners
= []
$maxRedirects
The maximum number of times we'll follow a redirect.
protected
int
$maxRedirects
= 5
$throwExceptions
Wether or not exceptions should be thrown when a HTTP error is returned.
protected
bool
$throwExceptions
= false
$curlHandle
Cached curl handle.
private
resource
$curlHandle
By keeping this resource around for the lifetime of this object, things like persistent connections are possible.
$curlMultiHandle
Handler for curl_multi requests.
private
resource
$curlMultiHandle
The first time sendAsync is used, this will be created.
$curlMultiMap
Has a list of curl handles, as well as their associated success and error callbacks.
private
array<string|int, mixed>
$curlMultiMap
= []
Methods
__construct()
Constructor.
public
__construct(array<string|int, mixed> $settings) : mixed
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
- $settings : array<string|int, mixed>
Return values
mixed —addCurlSetting()
Adds a CURL setting.
public
addCurlSetting(int $name, mixed $value) : mixed
These settings will be included in every HTTP request.
Parameters
- $name : int
- $value : mixed
Return values
mixed —emit()
Emits an event.
public
emit(string $eventName[, array<string|int, mixed> $arguments = [] ][, callable $continueCallBack = null ]) : bool
This method will return true if 0 or more listeners were successfully handled. false is returned if one of the events broke the event chain.
If the continueCallBack is specified, this callback will be called every time before the next event handler is called.
If the continueCallback returns false, event propagation stops. This allows you to use the eventEmitter as a means for listeners to implement functionality in your application, and break the event loop as soon as some condition is fulfilled.
Note that returning false from an event subscriber breaks propagation and returns false, but if the continue-callback stops propagation, this is still considered a 'successful' operation and returns true.
Lastly, if there are 5 event handlers for an event. The continueCallback will be called at most 4 times.
Parameters
- $eventName : string
- $arguments : array<string|int, mixed> = []
- $continueCallBack : callable = null
Return values
bool —getAbsoluteUrl()
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.
public
getAbsoluteUrl(string $url) : string
Parameters
- $url : string
Return values
string —listeners()
Returns the list of listeners for an event.
public
listeners(string $eventName) : array<string|int, callable>
The list is returned as an array, and the list of events are sorted by their priority.
Parameters
- $eventName : string
Return values
array<string|int, callable> —on()
Subscribe to an event.
public
on(string $eventName, callable $callBack[, int $priority = 100 ]) : mixed
Parameters
- $eventName : string
- $callBack : callable
- $priority : int = 100
Return values
mixed —once()
Subscribe to an event exactly once.
public
once(string $eventName, callable $callBack[, int $priority = 100 ]) : mixed
Parameters
- $eventName : string
- $callBack : callable
- $priority : int = 100
Return values
mixed —options()
Performs an HTTP options request.
public
options() : array<string|int, mixed>
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.
Return values
array<string|int, mixed> —parseMultiStatus()
Parses a WebDAV multistatus response body.
public
parseMultiStatus(string $body) : array<string|int, mixed>
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
- $body : string
-
xml body
Return values
array<string|int, mixed> —poll()
This method checks if any http requests have gotten results, and if so, call the appropriate success or error handlers.
public
poll() : bool
This method will return true if there are still requests waiting to return, and false if all the work is done.
Return values
bool —propFind()
Does a PROPFIND request.
public
propFind(string $url, array<string|int, mixed> $properties, int $depth) : array<string|int, mixed>
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
- $url : string
- $properties : array<string|int, mixed>
- $depth : int
Return values
array<string|int, mixed> —propPatch()
Updates a list of properties on the server.
public
propPatch(string $url, array<string|int, mixed> $properties) : bool
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
- $url : string
- $properties : array<string|int, mixed>
Return values
bool —removeAllListeners()
Removes all listeners.
public
removeAllListeners([string $eventName = null ]) : mixed
If the eventName argument is specified, all listeners for that event are removed. If it is not specified, every listener for every event is removed.
Parameters
- $eventName : string = null
Return values
mixed —removeListener()
Removes a specific listener from an event.
public
removeListener(string $eventName, callable $listener) : bool
If the listener could not be found, this method will return false. If it was removed it will return true.
Parameters
- $eventName : string
- $listener : callable
Return values
bool —request()
Performs an actual HTTP request, and returns the result.
public
request(string $method[, string $url = '' ][, string|resource|null $body = null ][, array<string|int, mixed> $headers = [] ]) : array<string|int, mixed>
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
- $method : string
- $url : string = ''
- $body : string|resource|null = null
- $headers : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed> —send()
Sends a request to a HTTP server, and returns a response.
public
send(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Return values
ResponseInterface —sendAsync()
Sends a HTTP request asynchronously.
public
sendAsync(RequestInterface $request[, callable $success = null ][, callable $error = null ]) : mixed
Due to the nature of PHP, you must from time to time poll to see if any new responses came in.
After calling sendAsync, you must therefore occasionally call the poll() method, or wait().
Parameters
- $request : RequestInterface
- $success : callable = null
- $error : callable = null
Return values
mixed —setThrowExceptions()
If this is set to true, the Client will automatically throw exceptions upon HTTP errors.
public
setThrowExceptions(bool $throwExceptions) : mixed
This means that if a response came back with a status code greater than or equal to 400, we will throw a ClientHttpException.
This only works for the send() method. Throwing exceptions for sendAsync() is not supported.
Parameters
- $throwExceptions : bool
Return values
mixed —wait()
Processes every HTTP request in the queue, and waits till they are all completed.
public
wait() : mixed
Return values
mixed —createCurlSettingsArray()
Turns a RequestInterface object into an array with settings that can be fed to curl_setopt.
protected
createCurlSettingsArray(RequestInterface $request) : array<string|int, mixed>
Parameters
- $request : RequestInterface
Return values
array<string|int, mixed> —curlExec()
Calls curl_exec.
protected
curlExec(resource $curlHandle) : string
This method exists so it can easily be overridden and mocked.
Parameters
- $curlHandle : resource
Return values
string —curlStuff()
Returns a bunch of information about a curl request.
protected
curlStuff(resource $curlHandle) : array<string|int, mixed>
This method exists so it can easily be overridden and mocked.
Parameters
- $curlHandle : resource
Return values
array<string|int, mixed> —doRequest()
This method is responsible for performing a single request.
protected
doRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Return values
ResponseInterface —parseCurlResponse()
Parses the result of a curl call in a format that's a bit more convenient to work with.
protected
parseCurlResponse(array<string|int, mixed> $headerLines, string $body, resource $curlHandle) : array<string|int, mixed>
The method returns an array with the following elements:
- status - one of the 3 STATUS constants.
- curl_errno - A curl error number. Only set if status is STATUS_CURLERROR.
- curl_errmsg - A current error message. Only set if status is STATUS_CURLERROR.
- response - Response object. Only set if status is STATUS_SUCCESS, or STATUS_HTTPERROR.
- http_code - HTTP status code, as an int. Only set if Only set if status is STATUS_SUCCESS, or STATUS_HTTPERROR
Parameters
- $headerLines : array<string|int, mixed>
- $body : string
- $curlHandle : resource
Return values
array<string|int, mixed> —parseCurlResult()
Parses the result of a curl call in a format that's a bit more convenient to work with.
protected
parseCurlResult(string $response, resource $curlHandle) : array<string|int, mixed>
The method returns an array with the following elements:
- status - one of the 3 STATUS constants.
- curl_errno - A curl error number. Only set if status is STATUS_CURLERROR.
- curl_errmsg - A current error message. Only set if status is STATUS_CURLERROR.
- response - Response object. Only set if status is STATUS_SUCCESS, or STATUS_HTTPERROR.
- http_code - HTTP status code, as an int. Only set if Only set if status is STATUS_SUCCESS, or STATUS_HTTPERROR
Parameters
- $response : string
- $curlHandle : resource
Tags
Return values
array<string|int, mixed> —receiveCurlHeader()
protected
receiveCurlHeader(mixed $curlHandle, mixed $headerLine) : mixed
Parameters
- $curlHandle : mixed
- $headerLine : mixed
Return values
mixed —sendAsyncInternal()
Sends an asynchronous HTTP request.
protected
sendAsyncInternal(RequestInterface $request, callable $success, callable $error, int $retryCount) : mixed
We keep this in a separate method, so we can call it without triggering the beforeRequest event and don't do the poll().
Parameters
- $request : RequestInterface
- $success : callable
- $error : callable
- $retryCount : int
Return values
mixed —parseResponse()
private
parseResponse(string $response, mixed $curlHandle) : array<string|int, mixed>
Parameters
- $response : string
- $curlHandle : mixed