Interface

eZClusterFileHandlerInterface

interface eZClusterFileHandlerInterface

Cluster file handlers interface

Methods

void fileStore(string $filePath, string $scope = false, bool $delete = false, string $datatype = false)

Stores a file by path to the backend

void fileStoreContents(string $filePath, string $contents, string $scope = false, string $datatype = false)

Store file contents.

storeContents(string $contents, string $scope = false, string $datatype = false, bool $storeLocally = false)

Store file contents using binary data

string|false fileFetch(string $filePath)

Fetches a file locally

processCache($retrieveCallback, $generateCallback = null, $ttl = null, $expiry = null, $extraData = null)

Handles cache requests / write operations

static bool isFileExpired(string $fname, int $mtime, int $expiry, int $curtime, int $ttl)

Calculates if the file data is expired or not.

bool isExpired(int $expiry, int $curtime, int $ttl)

Calculates if the current file data is expired or not.

bool isLocalFileExpired(int $expiry, int $curtime, int $ttl)

Calculates if the local file is expired or not.

bool isDBFileExpired(int $expiry, int $curtime, int $ttl)

Calculates if the DB file is expired or not.

processFile($callback, $expiry = false, $extraData = null)

Provides access to the file contents by downloading the file locally and calling $callback with the local filename.

string fetchUnique()

Fetches a cluster file and saves it locally under a new name

fetch(bool $noLocalCache = false)

Fetches file from db and saves it in FS under the same name.

string|bool fileFetchContents(string $filePath)

Returns file contents.

string|bool fetchContents()

Returns file contents.

void loadMetaData(bool $force = false)

Loads file meta information.

stat()

Returns file metadata.

int|null size()

Returns file size.

int|null mtime()

Returns file modification time.

string|null dataType()

Returns file mimetype / content type.

string name()

Returns file name.

fileDeleteByWildcard($wildcard)

fileDeleteByDirList($dirList, $commonPath, $commonSuffix)

fileDelete($path, $fnamePart = false)

Deletes specified file/directory.

delete()

Deletes specified file/directory.

fileDeleteLocal($path)

Deletes a file that has been fetched before.

deleteLocal()

Deletes a file that has been fetched before.

purge($printCallback = false, $microsleep = false, $max = false, $expiry = false)

Purges local and remote file data for current file.

bool fileExists($path)

Check if given file/dir exists.

bool exists()

Check if given file/dir exists.

passthrough()

Outputs file contents prepending them with appropriate HTTP headers.

fileCopy($srcPath, $dstPath)

Copy file.

fileLinkCopy($srcPath, $dstPath, $symLink)

Create symbolic or hard link to file.

fileMove($srcPath, $dstPath)

Move file.

move(string $dstPath)

Move file.

getFileList(array $scopes = false, boolean $excludeScopes = false)

Get list of files stored in database.

string|null storeCache(string|array $fileData)

Stores the data in $fileData to the remote and local file and commits the transaction.

bool startCacheGeneration()

Starts cache generation for the current file.

endCacheGeneration($rename = true)

Ends the cache generation started by startCacheGeneration().

abortCacheGeneration()

Aborts the current cache generation process.

checkCacheGenerationTimeout()

Checks if the .generating file was changed, which would mean that generation timed out.

bool requiresClusterizing()

This method indicates if the cluster file handler requires clusterizing.

bool requiresPurge()

This method indicates if the cluster file handler requires binary files to be purged in order to be physically deleted

bool hasStaleCacheSupport()

Indicates if the handler supports the stalecache feature

string applyServerUri(string $filePath)

Transforms $filePath so that it contains a valid href to the file, wherever it is stored.

Details

at line 27
public void fileStore(string $filePath, string $scope = false, bool $delete = false, string $datatype = false)

Stores a file by path to the backend

Parameters

string $filePath Path to the file being stored.
string $scope Means something like "file category". May be used to clean caches of a certain type.
bool $delete true if the file should be deleted after storing.
string $datatype

Return Value

void

at line 40
public void fileStoreContents(string $filePath, string $contents, string $scope = false, string $datatype = false)

Store file contents.

Parameters

string $filePath Path to the file being stored.
string $contents Binary file content
string $scope "file category". May be used by cache management
string $datatype Datatype for the file. Also used to clean cache up

Return Value

void

at line 51
public storeContents(string $contents, string $scope = false, string $datatype = false, bool $storeLocally = false)

Store file contents using binary data

Parameters

string $contents Binary file content
string $scope "file category". May be used by cache management
string $datatype Datatype for the file. Also used to clean cache up
bool $storeLocally If true the file will also be stored on the local file system.

at line 60
public string|false fileFetch(string $filePath)

Fetches a file locally

Parameters

string $filePath

Return Value

string|false the file path, or false if fetching failed

at line 128
public processCache($retrieveCallback, $generateCallback = null, $ttl = null, $expiry = null, $extraData = null)

Handles cache requests / write operations

Creates a single transaction out of the typical file operations for accessing caches. Caches are normally ready from the database or local file, if the entry does not exist or is expired then it generates the new cache data and stores it. This method takes care of these operations and handles the custom code by performing callbacks when needed.

The $retrieveCallback is used when the file contents can be used (ie. not re-generation) and is called when the file is ready locally. The function will be called with the file path as the first parameter, the mtime as the second and optionally $extraData as the third. The function must return the file contents or an instance of eZClusterFileFailure which can be used to tell the system that the retrieve data cannot be used after all.

$retrieveCallback can be set to null which makes the system go directly to the generation.

The $generateCallback is used when the file content is expired or does not exist, in this case the content must be re-generated and stored. The function will be called with the file path as the first parameter and optionally $extraData as the second. The function must return an array with information on the contents, the array consists of: - scope - The current scope of the file, is optional. - datatype - The current datatype of the file, is optional. - content - The file content, this can be any type except null. - binarydata - The binary data which is written to the file. - store - Whether content or binarydata should be stored to the file, if false it will simply return the data. Optional, by default it is true. Note: Set $generateCallback to false to disable generation callback. Note: Set $generateCallback to null to tell the function to perform a write lock but not do any generation, the generation must done be done by the caller by calling see storeCache().

Either content or binarydata must be supplied, if not an error is issued and it returns null.

If content is set it will be used as the return value of this function, if not it will return the binary data. If binarydata is set it will be used as the binary data for the file, if not it will perform a var_export on *content* and use that as the binary data.

For convenience the $generateCallback function can return a string which will be considered as the binary data for the file and returned as the content.

For controlling how long a cache entry can be used the parameters

Parameters

$retrieveCallback
$generateCallback
$ttl
$expiry
$extraData

See also

$expiry and @see $ttl is used.
$expiry can be set to a timestamp which controls the absolute max time for the cache, after this time/date the cache will never be used. If the value is set to a negative value or null there the expiration check is disabled. $ttl (time to live) tells how many seconds the cache can live from the time it was stored. If the value is set to negative or null there is no limit for the lifetime of the cache. A value of 0 means that the cache will always expire and practically disables caching. For the cache to be used both the $expiry and $ttl check must hold.

at line 143
static public bool isFileExpired(string $fname, int $mtime, int $expiry, int $curtime, int $ttl)

Calculates if the file data is expired or not.

Parameters

string $fname Name of file, available for easy debugging.
int $mtime Modification time of file, can be set to false if file does not exist.
int $expiry Time when file is to be expired, a value of -1 will disable this check.
int $curtime The current time to check against.
int $ttl Number of seconds the data can live, set to null to disable TTL.

Return Value

bool

at line 153
public bool isExpired(int $expiry, int $curtime, int $ttl)

Calculates if the current file data is expired or not.

Parameters

int $expiry Time when file is to be expired, a value of -1 will disable this check.
int $curtime The current time to check against.
int $ttl Number of seconds the data can live, set to null to disable TTL.

Return Value

bool

at line 162
public bool isLocalFileExpired(int $expiry, int $curtime, int $ttl)

Calculates if the local file is expired or not.

Parameters

int $expiry Time when file is to be expired, a value of -1 will disable this check.
int $curtime The current time to check against.
int $ttl Number of seconds the data can live, set to null to disable TTL.

Return Value

bool

at line 171
public bool isDBFileExpired(int $expiry, int $curtime, int $ttl)

Calculates if the DB file is expired or not.

Parameters

int $expiry Time when file is to be expired, a value of -1 will disable this check.
int $curtime The current time to check against.
int $ttl Number of seconds the data can live, set to null to disable TTL.

Return Value

bool

at line 187
public processFile($callback, $expiry = false, $extraData = null)

Provides access to the file contents by downloading the file locally and calling $callback with the local filename.

The callback can then process the contents and return the data in the same way as in processCache().

Downloading is only done once so the local copy is kept, while updates to the remote DB entry is synced with the local one.

The parameters $expiry and $extraData is the same as for processCache().

Parameters

$callback
$expiry
$extraData

See also

self::processCache()

at line 194
public string fetchUnique()

Fetches a cluster file and saves it locally under a new name

Return Value

string path to the saved file

at line 200
public fetch(bool $noLocalCache = false)

Fetches file from db and saves it in FS under the same name.

Parameters

bool $noLocalCache

at line 207
public string|bool fileFetchContents(string $filePath)

Returns file contents.

Parameters

string $filePath

Return Value

string|bool string, or false in case of an error.

at line 213
public string|bool fetchContents()

Returns file contents.

Return Value

string|bool contents string, or false in case of an error.

at line 221
public void loadMetaData(bool $force = false)

Loads file meta information.

Parameters

bool $force File stats will be refreshed if true

Return Value

void

at line 226
public stat()

Returns file metadata.

at line 232
public int|null size()

Returns file size.

Return Value

int|null

at line 238
public int|null mtime()

Returns file modification time.

Return Value

int|null

at line 244
public string|null dataType()

Returns file mimetype / content type.

Return Value

string|null

at line 250
public string name()

Returns file name.

Return Value

string

at line 255
public fileDeleteByWildcard($wildcard)

Parameters

$wildcard

at line 257
public fileDeleteByDirList($dirList, $commonPath, $commonSuffix)

Parameters

$dirList
$commonPath
$commonSuffix

at line 264
public fileDelete($path, $fnamePart = false)

Deletes specified file/directory.

If a directory specified it is deleted recursively.

Parameters

$path
$fnamePart

at line 271
public delete()

Deletes specified file/directory.

If a directory specified it is deleted recursively.

at line 276
public fileDeleteLocal($path)

Deletes a file that has been fetched before.

Parameters

$path

at line 281
public deleteLocal()

Deletes a file that has been fetched before.

at line 286
public purge($printCallback = false, $microsleep = false, $max = false, $expiry = false)

Purges local and remote file data for current file.

Parameters

$printCallback
$microsleep
$max
$expiry

at line 293
public bool fileExists($path)

Check if given file/dir exists.

Parameters

$path

Return Value

bool

at line 303
public bool exists()

Check if given file/dir exists.

Return Value

bool

at line 311
public passthrough()

Outputs file contents prepending them with appropriate HTTP headers.

at line 316
public fileCopy($srcPath, $dstPath)

Copy file.

Parameters

$srcPath
$dstPath

at line 321
public fileLinkCopy($srcPath, $dstPath, $symLink)

Create symbolic or hard link to file.

Parameters

$srcPath
$dstPath
$symLink

at line 326
public fileMove($srcPath, $dstPath)

Move file.

Parameters

$srcPath
$dstPath

at line 332
public move(string $dstPath)

Move file.

Parameters

string $dstPath Destination path

at line 343
public getFileList(array $scopes = false, boolean $excludeScopes = false)

Get list of files stored in database.

Used in bin/php/clusterize.php.

Parameters

array $scopes return only files that belong to any of these scopes
boolean $excludeScopes if true, then reverse the meaning of $scopes, which is return only files that do not belong to any of the scopes listed in $scopes

at line 359
public string|null storeCache(string|array $fileData)

Stores the data in $fileData to the remote and local file and commits the transaction.

The parameter $fileData must contain the same as information as the $generateCallback returns as explained in processCache().

This method is just a continuation of the code in processCache() and is not meant to be called alone since it relies on specific state in the database.

Parameters

string|array $fileData

Return Value

string|null

at line 369
public bool startCacheGeneration()

Starts cache generation for the current file.

This is done by creating a file named by the original file name, prefixed with '.generating'.

Return Value

bool false if the file is being generated, true if it is not

at line 374
public endCacheGeneration($rename = true)

Ends the cache generation started by startCacheGeneration().

Parameters

$rename

at line 382
public abortCacheGeneration()

Aborts the current cache generation process.

Does so by rolling back the current transaction, which should be the .generating file lock

at line 389
public checkCacheGenerationTimeout()

Checks if the .generating file was changed, which would mean that generation timed out.

If not timed out, refreshes the timestamp so that storage won't be stolen

at line 400
public bool requiresClusterizing()

This method indicates if the cluster file handler requires clusterizing.

If the handler does require clusterizing, it will be required/possible to use bin/php/clusterize.php to get data in/out of the cluster when setting it up or disabling it.

Return Value

bool

at line 409
public bool requiresPurge()

This method indicates if the cluster file handler requires binary files to be purged in order to be physically deleted

Return Value

bool

at line 415
public bool hasStaleCacheSupport()

Indicates if the handler supports the stalecache feature

Return Value

bool true if it does, false otherwise

at line 422
public string applyServerUri(string $filePath)

Transforms $filePath so that it contains a valid href to the file, wherever it is stored.

Parameters

string $filePath Example: /var/site/storage/images/example.png

Return Value

string http://static.example.com/var/site/storage/images/example.png