Path

ez components / documentation / api reference / trunk / webdav


eZ Components trunk

Webdav: ezcWebdavFileBackend

[ Tutorial ] [ Clients ] [ Plugin architecture ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcWebdavFileBackend

File system based backend. [source]

Implemented Interfaces

This backend serves WebDAV resources from a directory structure in the file system. It simply handles directories as collection resources and files as non-collection resources. The path to server resources from is defined during construction.
 1.   $backend new ezcWebdavFileBackend(
 2.       'directory/'
 3.   );
Live properties are partly determined from the file systems itself (like ezcWebdavGetContentLengthProperty), others need to be stored like dead properties. This backend uses a special path for each resource to store this information in its XML representation.

Parents

ezcWebdavBackend
   |
   --ezcWebdavSimpleBackend
      |
      --ezcWebdavFileBackend

Inherited Constants

From ezcWebdavBackend:
ezcWebdavBackend::COMPRESSION_BZIP2    Backend has native support for bzip2 compression.
ezcWebdavBackend::COMPRESSION_GZIP    Backend has native support for gzip compression.
ezcWebdavBackend::CUSTOM_LOCK    Backend performs locking itself - no handling by server is required.
ezcWebdavBackend::MULTIPART    Backend has native support for multipart requests.
ezcWebdavBackend::PARTIAL    Backend has native support for partial requests.

Member Variables

protected array(int=>string) $handledLiveProperties = array(
'getcontentlength',
'getlastmodified',
'creationdate',
'displayname',
'getetag',
'getcontenttype',
'resourcetype',
'supportedlock',
'lockdiscovery',
)

Names of live properties from the DAV: namespace which will be handled live, and should not be stored like dead properties.
protected int $lockLevel = 0
Keeps track of the lock level.

Each time the lock() method is called, this counter is raised by 1. if it was 0 before, the actual locking mechanism gets into action, otherwise just the counter is raised. The lock is physically only freed, if this counter is 0.
This mechanism allows nested locking, as it is necessary, if the lock plugin locks this backend external, but interal locking needs still to be supported.
protected ezcWebdavFileBackendOptions $options
Options.
protected string $root
Root directory to serve content from. All paths are seen relatively to this one.

Method Summary

public void __construct( $root )
Creates a new backend instance.
protected void acquireLock( [$readOnly = false] )
Wait and get lock for complete directory tree.
public array checkDeleteRecursive( $source )
Returns if everything below a path can be deleted recursively.
public ezcWebdavResponse copy( $request )
Serves COPY requests.
public array copyRecursive( $source, $destination, [$depth = ezcWebdavRequest::DEPTH_INFINITY] )
Recursively copy a file or directory.
protected void createCollection( $path )
Creates a new collection.
protected void createResource( $path, [$content = null] )
Creates a new resource.
public ezcWebdavResponse delete( $request )
Serves DELETE requests.
protected void freeLock( )
Free lock.
public ezcWebdavResponse get( $request )
Serves GET requests.
public ezcWebdavPropertyStorage getAllProperties( $path )
Returns all properties for a resource.
protected array(ezcWebdavResource|ezcWebdavCollection) getCollectionMembers( $path )
Returns members of collection.
protected void getETag( $path )
Returns the etag representing the current state of $path.
protected string getMimeType( $path )
Returns the mime type of a resource.
public ezcWebdavProperty getProperty( $path, $propertyName, [$namespace = 'DAV:'] )
Returns a property of a resource.
protected ezcWebdavBasicPropertyStorage getPropertyStorage( $path )
Returns the property storage for a resource.
protected string getPropertyStoragePath( $path )
Returns the storage path for a property.
protected string getResourceContents( $path )
Returns the contents of a resource.
public ezcWebdavResponse head( $request )
Serves HEAD requests.
protected bool isCollection( $path )
Returns if resource is a collection.
public void lock( $waitTime, $timeout )
Locks the backend.
public ezcWebdavResponse makeCollection( $request )
Serves MKCOL (make collection) requests.
public ezcWebdavResponse move( $request )
Serves MOVE requests.
protected bool nodeExists( $path )
Returns if a resource exists.
protected array(ezcWebdavErrorResponse) performCopy( $fromPath, $toPath, [$depth = ezcWebdavRequest::DEPTH_INFINITY] )
Copies resources recursively from one path to another.
protected ezcWebdavErrorResponse performDelete( $path )
Deletes everything below a path.
public ezcWebdavResponse propFind( $request )
Serves PROPFIND requests.
public ezcWebdavResponse propPatch( $request )
Serves PROPPATCH requests.
public ezcWebdavResponse put( $request )
Serves PUT requests.
public bool removeProperty( $path, $property )
Manually removes a property from a resource.
public bool resetProperties( $path, $storage )
Resets the property storage for a resource.
public bool setProperty( $path, $property )
Manually sets a property on a resource.
protected void setResourceContents( $path, $content )
Sets the contents of a resource.
protected void storeProperties( $path, $storage )
Stores properties for a resource.
public void unlock( )
Removes the lock.

Inherited Methods

From ezcWebdavSimpleBackend :
protected ezcWebdavErrorResponse|null ezcWebdavSimpleBackend::checkIfMatchHeaders()
Checks the If-Match and If-None-Match headers.
public ezcWebdavResponse ezcWebdavSimpleBackend::copy()
Serves COPY requests.
protected abstract void ezcWebdavSimpleBackend::createCollection()
Create a new collection.
protected abstract void ezcWebdavSimpleBackend::createResource()
Create a new resource.
public ezcWebdavResponse ezcWebdavSimpleBackend::delete()
Serves DELETE requests.
protected ezcWebdavMultistatusResponse ezcWebdavSimpleBackend::fetchAllProperties()
Returns all available properties for a resource.
protected ezcWebdavResponse ezcWebdavSimpleBackend::fetchProperties()
Returns properties, fetched by name.
protected ezcWebdavResponse ezcWebdavSimpleBackend::fetchPropertyNames()
Returns names of all available properties for a resource.
public ezcWebdavResponse ezcWebdavSimpleBackend::get()
Serves GET requests.
public abstract ezcWebdavPropertyStorage ezcWebdavSimpleBackend::getAllProperties()
Returns all properties for a resource.
protected abstract array(ezcWebdavResource|ezcWebdavCollection) ezcWebdavSimpleBackend::getCollectionMembers()
Returns members of collection.
protected void ezcWebdavSimpleBackend::getETag()
Returns the etag representing the current state of $path.
public int ezcWebdavSimpleBackend::getFeatures()
Returns additional features supported by the backend.
protected array(ezcWebdavResource|ezcWebdavCollection) ezcWebdavSimpleBackend::getNodes()
Returns all child nodes.
public abstract ezcWebdavProperty ezcWebdavSimpleBackend::getProperty()
Returns a property of a resource.
protected abstract string ezcWebdavSimpleBackend::getResourceContents()
Returns the content of a resource.
public ezcWebdavResponse ezcWebdavSimpleBackend::head()
Serves HEAD requests.
protected abstract bool ezcWebdavSimpleBackend::isCollection()
Returns if resource is a collection.
public ezcWebdavResponse ezcWebdavSimpleBackend::makeCollection()
Serves MKCOL (make collection) requests.
public ezcWebdavResponse ezcWebdavSimpleBackend::move()
Serves MOVE requests.
protected abstract bool ezcWebdavSimpleBackend::nodeExists()
Returns if a resource exists.
public ezcWebdavOptionsResponse ezcWebdavSimpleBackend::options()
Handles the OPTIONS request.
protected abstract array(ezcWebdavErrorResponse) ezcWebdavSimpleBackend::performCopy()
Copies resources recursively from one path to another.
protected abstract ezcWebdavMultitstatusResponse|null ezcWebdavSimpleBackend::performDelete()
Deletes everything below a path.
public ezcWebdavResponse ezcWebdavSimpleBackend::propFind()
Serves PROPFIND requests.
public ezcWebdavResponse ezcWebdavSimpleBackend::propPatch()
Serves PROPPATCH requests.
public ezcWebdavResponse ezcWebdavSimpleBackend::put()
Serves PUT requests.
public abstract bool ezcWebdavSimpleBackend::removeProperty()
Manually removes a property from a resource.
public abstract bool ezcWebdavSimpleBackend::resetProperties()
Resets the property storage for a resource.
public abstract bool ezcWebdavSimpleBackend::setProperty()
Manually sets a property on a resource.
protected abstract void ezcWebdavSimpleBackend::setResourceContents()
Changes contents of a resource.
From ezcWebdavBackend :
public abstract ezcWebdavResponse ezcWebdavBackend::get()
Serves GET requests.
public int ezcWebdavBackend::getFeatures()
Returns additional features supported by the backend.
public abstract ezcWebdavResponse ezcWebdavBackend::head()
Serves HEAD requests.
public ezcWebdavResponse ezcWebdavBackend::options()
Required method to serve OPTIONS requests.
public ezcWebdavResponse ezcWebdavBackend::performRequest()
Performs the given request.
public abstract ezcWebdavResponse ezcWebdavBackend::propFind()
Serves PROPFIND requests.
public abstract ezcWebdavResponse ezcWebdavBackend::propPatch()
Serves PROPPATCH requests.

Methods

__construct

void __construct( string $root )
Creates a new backend instance.
Creates a new backend to server WebDAV content from the file system path identified by $root. If the given path does not exist or is not a directory, an exception will be thrown.

Parameters

Name Type Description
$root string  

Throws

ClassDescription
ezcBaseFilePermissionException if the given $root is not readable.
ezcBaseFileNotFoundException if the given $root does not exist or is not a directory.

acquireLock

void acquireLock( [bool $readOnly = false] )
Wait and get lock for complete directory tree.
Acquire lock for the complete tree for read or write operations. This does not implement any priorities for operations, or check if several read operation may run in parallel. The plain locking should / could be extended by something more sophisticated.
If the tree already has been locked, the method waits until the lock can be acquired.
The optional second parameter $readOnly indicates wheather a read only lock should be acquired. This may be used by extended implementations, but it is not used in this implementation.

Parameters

Name Type Description
$readOnly bool  

checkDeleteRecursive

array checkDeleteRecursive( string $source )
Returns if everything below a path can be deleted recursively.
Checks files and directories recursively and returns if everything can be deleted. Returns an empty array if no errors occured, and an array with the files which caused errors otherwise.

Parameters

Name Type Description
$source string  

copy

Serves COPY requests.
The method receives a ezcWebdavCopyRequest objects containing all relevant information obout the clients request and will return an instance of ezcWebdavErrorResponse on error or ezcWebdavCopyResponse on success. If only some operations failed, this method may return an instance of ezcWebdavMultistatusResponse.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavCopyRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::copy() Serves COPY requests.

copyRecursive

array copyRecursive( string $source, string $destination, [int $depth = ezcWebdavRequest::DEPTH_INFINITY] )
Recursively copy a file or directory.
Recursively copy a file or directory in $source to the given $destination. If a $depth is given, the operation will stop as soon as the given recursion depth is reached. A depth of -1 means no limit, while a depth of 0 means, that only the current file or directory will be copied, without any recursion.
Returns an empty array if no errors occured, and an array with the files which caused errors otherwise.

Parameters

Name Type Description
$source string  
$destination string  
$depth int  

createCollection

void createCollection( string $path )
Creates a new collection.
Creates a new collection at the given $path.

Parameters

Name Type Description
$path string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::createCollection() Create a new collection.

createResource

void createResource( string $path, [string $content = null] )
Creates a new resource.
Creates a new resource at the given $path, optionally with the given content. If $content is empty, an empty resource will be created.

Parameters

Name Type Description
$path string  
$content string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::createResource() Create a new resource.

delete

Serves DELETE requests.
The method receives a ezcWebdavDeleteRequest objects containing all relevant information obout the clients request and will return an instance of ezcWebdavErrorResponse on error or ezcWebdavDeleteResponse on success.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavDeleteRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::delete() Serves DELETE requests.

freeLock

void freeLock( )
Free lock.
Frees the lock after the operation has been finished.

get

Serves GET requests.
The method receives a ezcWebdavGetRequest object containing all relevant information obout the clients request and will return an ezcWebdavErrorResponse instance on error or an instance of ezcWebdavGetResourceResponse or ezcWebdavGetCollectionResponse on success, depending on the type of resource that is referenced by the request.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavGetRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::get() Serves GET requests.

getAllProperties

ezcWebdavPropertyStorage getAllProperties( string $path )
Returns all properties for a resource.
Returns all properties for the resource identified by $path as a ezcWebdavBasicPropertyStorage.

Parameters

Name Type Description
$path string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::getAllProperties() Returns all properties for a resource.

getCollectionMembers

array(ezcWebdavResource|ezcWebdavCollection) getCollectionMembers( string $path )
Returns members of collection.
Returns an array with the members of the collection identified by $path. The returned array can contain ezcWebdavCollection, and ezcWebdavResource instances and might also be empty, if the collection has no members.

Parameters

Name Type Description
$path string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::getCollectionMembers() Returns members of collection.

getETag

void getETag( mixed $path )
Returns the etag representing the current state of $path.
Calculates and returns the ETag for the resource represented by $path. The ETag is calculated from the $path itself and the following properties, which are concatenated and md5 hashed:
  • getcontentlength
  • getlastmodified
This method can be overwritten in custom backend implementations to access the information needed directly without using the way around properties.
Custom backend implementations are encouraged to use the same mechanism (or this method itself) to determine and generate ETags.

Parameters

Name Type Description
$path mixed  

Redefinition of

Method Description
ezcWebdavSimpleBackend::getETag() Returns the etag representing the current state of $path.

getMimeType

string getMimeType( string $path )
Returns the mime type of a resource.
Return the mime type of the resource identified by $path. If a mime type extension is available it will be used to read the real mime type, otherwise the original mime type passed by the client when uploading the file will be returned. If no mimetype has ever been associated with the file, the method will just return 'application/octet-stream'.

Parameters

Name Type Description
$path string  

getProperty

ezcWebdavProperty getProperty( string $path, string $propertyName, [string $namespace = 'DAV:'] )
Returns a property of a resource.
Returns the property with the given $propertyName, from the resource identified by $path. You may optionally define a $namespace to receive the property from.

Parameters

Name Type Description
$path string  
$propertyName string  
$namespace string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::getProperty() Returns a property of a resource.

getPropertyStorage

ezcWebdavBasicPropertyStorage getPropertyStorage( string $path )
Returns the property storage for a resource.
Returns the ezcWebdavPropertyStorage instance containing the properties for the resource identified by $path.

Parameters

Name Type Description
$path string  

getPropertyStoragePath

string getPropertyStoragePath( string $path )
Returns the storage path for a property.
Returns the file systems path where properties are stored for the resource identified by $path. This depends on the name of the resource.

Parameters

Name Type Description
$path string  

getResourceContents

string getResourceContents( string $path )
Returns the contents of a resource.
This method returns the content of the resource identified by $path as a string.

Parameters

Name Type Description
$path string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::getResourceContents() Returns the content of a resource.

head

Serves HEAD requests.
The method receives a ezcWebdavHeadRequest object containing all relevant information obout the clients request and will return an ezcWebdavErrorResponse instance on error or an instance of ezcWebdavHeadResponse on success.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavHeadRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::head() Serves HEAD requests.

isCollection

bool isCollection( string $path )
Returns if resource is a collection.
Returns if the resource identified by $path is a collection resource (true) or a non-collection one (false).

Parameters

Name Type Description
$path string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::isCollection() Returns if resource is a collection.

lock

void lock( int $waitTime, int $timeout )
Locks the backend.
Tries to lock the backend. If the lock is already owned by this process, locking is successful. If $timeout is reached before a lock could be acquired, an ezcWebdavLockTimeoutException is thrown. Waits $waitTime microseconds between attempts to lock the backend.

Parameters

Name Type Description
$waitTime int  
$timeout int  

makeCollection

Serves MKCOL (make collection) requests.
The method receives a ezcWebdavMakeCollectionRequest objects containing all relevant information obout the clients request and will return an instance of ezcWebdavErrorResponse on error or ezcWebdavMakeCollectionResponse on success.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavMakeCollectionRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::makeCollection() Serves MKCOL (make collection) requests.

move

Serves MOVE requests.
The method receives a ezcWebdavMoveRequest objects containing all relevant information obout the clients request and will return an instance of ezcWebdavErrorResponse on error or ezcWebdavMoveResponse on success. If only some operations failed, this method may return an instance of ezcWebdavMultistatusResponse.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavMoveRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::move() Serves MOVE requests.

nodeExists

bool nodeExists( string $path )
Returns if a resource exists.
Returns if a the resource identified by $path exists.

Parameters

Name Type Description
$path string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::nodeExists() Returns if a resource exists.

performCopy

array(ezcWebdavErrorResponse) performCopy( string $fromPath, string $toPath, [int $depth = ezcWebdavRequest::DEPTH_INFINITY] )
Copies resources recursively from one path to another.
Copies the resourced identified by $fromPath recursively to $toPath with the given $depth, where $depth is one of ezcWebdavRequest::DEPTH_ZERO, ezcWebdavRequest::DEPTH_ONE, ezcWebdavRequest::DEPTH_INFINITY.
Returns an array with ezcWebdavErrorResponses for all subtrees, where the copy operation failed. Errors for subsequent resources in a subtree should be ommitted.
If an empty array is return, the operation has been completed successfully.

Parameters

Name Type Description
$fromPath string  
$toPath string  
$depth int  

Redefinition of

Method Description
ezcWebdavSimpleBackend::performCopy() Copies resources recursively from one path to another.

performDelete

ezcWebdavErrorResponse performDelete( string $path )
Deletes everything below a path.
Deletes the resource identified by $path recursively. Returns an instance of ezcWebdavErrorResponse if the deletion failed, and null on success.

Parameters

Name Type Description
$path string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::performDelete() Deletes everything below a path.

propFind

Serves PROPFIND requests.
The method receives a ezcWebdavPropFindRequest object containing all relevant information obout the clients request and will either return an instance of ezcWebdavErrorResponse to indicate an error or a ezcWebdavPropFindResponse on success. If the referenced resource is a collection or if some properties produced errors, an instance of ezcWebdavMultistatusResponse may be returned.
The ezcWebdavPropFindRequest object contains a definition to find one or more properties of a given collection or non-collection resource.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavPropFindRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::propFind() Serves PROPFIND requests.

propPatch

Serves PROPPATCH requests.
The method receives a ezcWebdavPropPatchRequest object containing all relevant information obout the clients request and will return an instance of ezcWebdavErrorResponse on error or a ezcWebdavPropPatchResponse response on success. If the referenced resource is a collection or if only some properties produced errors, an instance of ezcWebdavMultistatusResponse may be returned.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavPropPatchRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::propPatch() Serves PROPPATCH requests.

put

Serves PUT requests.
The method receives a ezcWebdavPutRequest objects containing all relevant information obout the clients request and will return an instance of ezcWebdavErrorResponse on error or ezcWebdavPutResponse on success.
This method acquires the internal lock of the backend, dispatches to ezcWebdavSimpleBackend to perform the operation and releases the lock afterwards.

Parameters

Name Type Description
$request ezcWebdavPutRequest  

Redefinition of

Method Description
ezcWebdavSimpleBackend::put() Serves PUT requests.

removeProperty

bool removeProperty( string $path, ezcWebdavProperty $property )
Manually removes a property from a resource.
Removes the given $property form the resource identified by $path.

Parameters

Name Type Description
$path string  
$property ezcWebdavProperty  

Redefinition of

Method Description
ezcWebdavSimpleBackend::removeProperty() Manually removes a property from a resource.

resetProperties

bool resetProperties( string $path, ezcWebdavPropertyStorage $storage )
Resets the property storage for a resource.
Discardes the current ezcWebdavPropertyStorage of the resource identified by $path and replaces it with the given $properties.

Parameters

Name Type Description
$path string  
$storage ezcWebdavPropertyStorage  

Redefinition of

Method Description
ezcWebdavSimpleBackend::resetProperties() Resets the property storage for a resource.

setProperty

bool setProperty( string $path, ezcWebdavProperty $property )
Manually sets a property on a resource.
Sets the given $propertyBackup for the resource identified by $path.

Parameters

Name Type Description
$path string  
$property ezcWebdavProperty  

Redefinition of

Method Description
ezcWebdavSimpleBackend::setProperty() Manually sets a property on a resource.

setResourceContents

void setResourceContents( string $path, string $content )
Sets the contents of a resource.
This method replaces the content of the resource identified by $path with the submitted $content.

Parameters

Name Type Description
$path string  
$content string  

Redefinition of

Method Description
ezcWebdavSimpleBackend::setResourceContents() Changes contents of a resource.

storeProperties

void storeProperties( string $path, ezcWebdavBasicPropertyStorage $storage )
Stores properties for a resource.
Creates a new property storage file and stores the properties given for the resource identified by $path. This depends on the affected resource and the actual properties in the property storage.

Parameters

Name Type Description
$path string  
$storage ezcWebdavBasicPropertyStorage  

unlock

void unlock( )
Removes the lock.

Last updated: Mon, 21 Dec 2009