PHP Class Jyxo\Webdav\Client

Author: Jaroslav HanslĂ­k
Show file Open project: jyxo/php Class Usage Examples

Protected Properties

Property Type Description
$createDirectoriesAutomatically boolean If disabled, commands will throw an error if target directory doesn't exist.
$logger Jyxo\Webdav\LoggerInterface Logger.
$parallelSending boolean If parallel request sending is enabled.
$requestOptions array Request options.
$servers array Servers list.

Public Methods

Method Description
__construct ( array $servers ) Constructor.
copy ( string $pathFrom, string $pathTo ) Copies a file.
exists ( string $path ) : boolean Checks if a file exists.
get ( string $path ) : string Returns file contents.
getProperty ( string $path, string $property = null ) : mixed Returns a file property.
isDir ( string $dir ) : boolean Checks if a directory exists.
mkdir ( string $dir, boolean $recursive = true ) Creates a directory.
put ( string $path, string $data ) Saves data to a remote file.
putFile ( string $path, string $file ) Saves file contents to a remote file.
rename ( string $pathFrom, string $pathTo ) Renames a file.
rmdir ( string $dir ) Deletes a directory.
setCreateDirectoriesAutomatically ( boolean $createDirectoriesAutomatically ) : self Enables/disables automatic creation of target directories.
setLogger ( Jyxo\Webdav\LoggerInterface $logger ) : self Sets a logger.
setParallelSending ( boolean $parallelSending ) : self Enables/disables parallel request sending.
setRequestOption ( string $name, mixed $value ) : self Sets a request option.
unlink ( string $path ) Deletes a file.

Protected Methods

Method Description
createAllRequests ( string $path, string $method, array $headers = [], string | resource | null $body = null ) : array Creates a list of requests; one for each server.
createClient ( ) : Client
createRequest ( string $server, string $path, string $method, array $headers = [], string | resource | null $body = null ) : GuzzleHttp\Psr7\Request Creates a request.
getDirPath ( string $path ) : string Creates a directory path with the trailing slash.
getFilePath ( string $path ) : string Creates a file path without the trailing slash.
getProperties ( Response $response ) : array Fetches properties from the response.
getRandomServer ( ) : string
processPut ( string $path, string $data, boolean $isFile ) Processes a PUT request.
sendAllRequests ( array $requests ) : array Sends requests to all servers.
sendRequest ( string $path, string $method, array $headers = [] ) : Response Sends a request.

Method Details

__construct() public method

Constructor.
public __construct ( array $servers )
$servers array

copy() public method

Does not work on Lighttpd.
public copy ( string $pathFrom, string $pathTo )
$pathFrom string Source file path
$pathTo string Target file path

createAllRequests() protected method

Creates a list of requests; one for each server.
protected createAllRequests ( string $path, string $method, array $headers = [], string | resource | null $body = null ) : array
$path string Request path
$method string Request method
$headers array Array of headers
$body string | resource | null Request body
return array

createClient() protected method

protected createClient ( ) : Client
return GuzzleHttp\Client

createRequest() protected method

Creates a request.
protected createRequest ( string $server, string $path, string $method, array $headers = [], string | resource | null $body = null ) : GuzzleHttp\Psr7\Request
$server string Server
$path string Path
$method string Request method
$headers array Array of headers
$body string | resource | null Request body
return GuzzleHttp\Psr7\Request

exists() public method

Checks if a file exists.
public exists ( string $path ) : boolean
$path string File path
return boolean

get() public method

Returns file contents.
public get ( string $path ) : string
$path string File path
return string

getDirPath() protected method

Creates a directory path with the trailing slash.
protected getDirPath ( string $path ) : string
$path string Directory path
return string

getFilePath() protected method

Creates a file path without the trailing slash.
protected getFilePath ( string $path ) : string
$path string File path
return string

getProperties() protected method

Fetches properties from the response.
protected getProperties ( Response $response ) : array
$response GuzzleHttp\Psr7\Response Response
return array

getProperty() public method

If no particular property is set, all properties are returned.
public getProperty ( string $path, string $property = null ) : mixed
$path string File path
$property string Property name
return mixed

getRandomServer() protected method

protected getRandomServer ( ) : string
return string

isDir() public method

Checks if a directory exists.
public isDir ( string $dir ) : boolean
$dir string Directory path
return boolean

mkdir() public method

Creates a directory.
public mkdir ( string $dir, boolean $recursive = true )
$dir string Directory path
$recursive boolean Create directories recursively?

processPut() protected method

Processes a PUT request.
protected processPut ( string $path, string $data, boolean $isFile )
$path string File path
$data string Data
$isFile boolean Determines if $data is a file name or actual data

put() public method

Saves data to a remote file.
public put ( string $path, string $data )
$path string File path
$data string Data

putFile() public method

Saves file contents to a remote file.
public putFile ( string $path, string $file )
$path string File path
$file string Local file path

rename() public method

Does not work on Lighttpd.
public rename ( string $pathFrom, string $pathTo )
$pathFrom string Original file name
$pathTo string New file name

rmdir() public method

Deletes a directory.
public rmdir ( string $dir )
$dir string Directory path

sendAllRequests() protected method

Sends requests to all servers.
protected sendAllRequests ( array $requests ) : array
$requests array Request list
return array

sendRequest() protected method

Sends a request.
protected sendRequest ( string $path, string $method, array $headers = [] ) : Response
$path string Request path
$method string Request method
$headers array Array of headers
return GuzzleHttp\Psr7\Response

setCreateDirectoriesAutomatically() public method

Enables/disables automatic creation of target directories.
public setCreateDirectoriesAutomatically ( boolean $createDirectoriesAutomatically ) : self
$createDirectoriesAutomatically boolean
return self

setLogger() public method

Sets a logger.
public setLogger ( Jyxo\Webdav\LoggerInterface $logger ) : self
$logger Jyxo\Webdav\LoggerInterface Logger
return self

setParallelSending() public method

Enables/disables parallel request sending.
public setParallelSending ( boolean $parallelSending ) : self
$parallelSending boolean
return self

setRequestOption() public method

Sets a request option.
See also: GuzzleHttp\RequestOptions
public setRequestOption ( string $name, mixed $value ) : self
$name string Option name
$value mixed Option value
return self

Property Details

$createDirectoriesAutomatically protected property

If disabled, commands will throw an error if target directory doesn't exist.
protected bool $createDirectoriesAutomatically
return boolean

$logger protected property

Logger.
protected LoggerInterface,Jyxo\Webdav $logger
return Jyxo\Webdav\LoggerInterface

$parallelSending protected property

If parallel request sending is enabled.
protected bool $parallelSending
return boolean

$requestOptions protected property

Request options.
protected array $requestOptions
return array

$servers protected property

Servers list.
protected array $servers
return array