eZ Publish  [trunk]
eZFSFileHandler Class Reference
+ Inheritance diagram for eZFSFileHandler:

List of all members.

Public Member Functions

 abortCacheGeneration ()
 Aborts the current cache generation process.
 checkCacheGenerationTimeout ()
 Checks if the .generating file was changed, which would mean that generation timed out.
 deleteLocal ()
 Deletes a file that has been fetched before.
 endCacheGeneration ()
 Ends the cache generation started by startCacheGeneration().
 exists ()
 Check if given file/dir exists.
 eZFSFileHandler ($filePath=false)
 Constructor.
 fetch ($noLocalCache=false)
 Fetches file from db and saves it in FS under the same name.
 fetchContents ()
 Returns file contents.
 fetchUnique ()
 Fetches file from db and saves it in FS under unique name.
 fileDeleteLocal ($path)
 Deletes a file that has been fetched before.
 fileFetch ($filePath)
 Fetches file from db and saves it in FS under the same name.
 fileFetchContents ($filePath)
 Returns file contents.
 fileStore ($filePath, $scope=false, $delete=false, $datatype=false)
 Store file.
 hasStaleCacheSupport ()
 isExpired ($expiry, $curtime, $ttl)
 Calculates if the current file data is expired or not.
 loadMetaData ($force=false)
 move ($dstPath)
 Move file.
 mtime ()
 Returns file modification time.
 name ()
 Returns file name.
 passthrough ($offset=0, $length=false)
 Outputs file contents to the browser Note: does not handle headers.
 processCache ($retrieveCallback, $generateCallback=null, $ttl=null, $expiry=null, $extraData=null)
 processFile ($callback, $expiry=false, $extraData=null)
 purge ($printCallback=false, $microsleep=false, $max=false, $expiry=false)
 requiresBinaryPurge ()
 eZFS does not require binary purge.
 requiresClusterizing ()
 eZFS only stores data to FS and doesn't require/support clusterizing
 requiresPurge ()
 eZFS does not require binary purge.
 size ()
 Returns file size.
 startCacheGeneration ()
 Starts cache generation for the current file.
 stat ()
 Returns file metadata.
 storeContents ($contents, $scope=false, $datatype=false, $storeLocally=false)
 Store file contents to disk.

Static Public Member Functions

 delete ()
 Deletes specified file/directory.
 fileCopy ($srcPath, $dstPath)
 Copy file.
 fileDelete ($path, $fnamePart=false)
 fileDeleteByDirList ($dirList, $commonPath, $commonSuffix)
 Delete files located in a directories from dirList, with common prefix specified by commonPath, and common suffix with added wildcard at the end.
 fileDeleteByRegex ($dir, $fileRegex)
 Delete files matching regex $fileRegex under directory $dir.
 fileDeleteByWildcard ($wildcard)
 Delete files matching given wildcard.
 fileExists ($path)
 Check if given file/dir exists.
 fileLinkCopy ($srcPath, $dstPath, $symLink)
 Create symbolic or hard link to file.
 fileMove ($srcPath, $dstPath)
 Move file.
 fileStoreContents ($filePath, $contents, $scope=false, $datatype=false)
 Store file contents.
static isFileExpired ($fname, $mtime, $expiry, $curtime, $ttl)
 Calculates if the file data is expired or not.

Public Attributes

 $filePath
 $metaData = null
const EXPIRY_TIMESTAMP = 233366400
 This should be defined in eZFS2FileHandler, but due to static members limitations in PHP < 5.3, it is declared here.

Private Member Functions

 _exclusiveLock ($fname=false)
 _freeExclusiveLock ($fname=false)
_mutex ()
 storeCache ($fileData, $storeCache=true)

Detailed Description

Definition at line 11 of file ezfsfilehandler.php.


Member Function Documentation

eZFSFileHandler::_exclusiveLock ( fname = false) [private]

Acquires an exclusive lock to the current file by using eZMutex.

If a lock is already present it will sleep 0.5 seconds and try again until the lock lifetime is exceeded and the lock is stolen.

Note: Lock stealing might be removed.

Parameters:
$fnameName of the calling code (usually function name).

Definition at line 44 of file ezfsfilehandler.php.

Referenced by processCache().

eZFSFileHandler::_freeExclusiveLock ( fname = false) [private]

Frees the current exclusive lock in use.

Parameters:
$fnameName of the calling code (usually function name).

Definition at line 89 of file ezfsfilehandler.php.

Referenced by processCache(), and storeCache().

& eZFSFileHandler::_mutex ( ) [private]

Returns the mutex object for the current file.

Definition at line 99 of file ezfsfilehandler.php.

Referenced by _exclusiveLock(), and _freeExclusiveLock().

Aborts the current cache generation process.

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

Reimplemented in eZFS2FileHandler.

Definition at line 996 of file ezfsfilehandler.php.

Referenced by storeCache().

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

Reimplemented in eZFS2FileHandler.

Definition at line 1006 of file ezfsfilehandler.php.

Deletes specified file/directory.

If a directory specified it is deleted recursively.

Reimplemented in eZFS2FileHandler.

Definition at line 746 of file ezfsfilehandler.php.

Deletes a file that has been fetched before.

In case of fetching from filesystem does nothing.

Reimplemented in eZFS2FileHandler.

Definition at line 792 of file ezfsfilehandler.php.

Ends the cache generation started by startCacheGeneration().

Definition at line 985 of file ezfsfilehandler.php.

Referenced by eZFS2FileHandler\storeCache().

Check if given file/dir exists.

NOTE: this function does not interact with filesystem. Instead, it just returns existance status determined in the constructor.

Reimplemented in eZFS2FileHandler.

Definition at line 880 of file ezfsfilehandler.php.

Constructor.

$filePath File path. If specified, file metadata is fetched in the constructor.

Definition at line 24 of file ezfsfilehandler.php.

eZFSFileHandler::fetch ( noLocalCache = false)

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

In case of fetching from filesystem does nothing.

Definition at line 145 of file ezfsfilehandler.php.

Returns file contents.

Returns:
contents string, or false in case of an error.

Definition at line 245 of file ezfsfilehandler.php.

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

In case of fetching from filesystem, does nothing

Returns:
string The unique file path. on FS, the file path.

Definition at line 158 of file ezfsfilehandler.php.

eZFSFileHandler::fileCopy ( srcPath,
dstPath 
) [static]

Copy file.

Definition at line 911 of file ezfsfilehandler.php.

eZFSFileHandler::fileDelete ( path,
fnamePart = false 
) [static]

Reimplemented in eZFS2FileHandler.

Definition at line 700 of file ezfsfilehandler.php.

eZFSFileHandler::fileDeleteByDirList ( dirList,
commonPath,
commonSuffix 
) [static]

Delete files located in a directories from dirList, with common prefix specified by commonPath, and common suffix with added wildcard at the end.

See also:
fileDeleteByRegex()

Reimplemented in eZFS2FileHandler.

Definition at line 680 of file ezfsfilehandler.php.

eZFSFileHandler::fileDeleteByRegex ( dir,
fileRegex 
) [static]

Delete files matching regex $fileRegex under directory $dir.

See also:
fileDeleteByWildcard()

Definition at line 607 of file ezfsfilehandler.php.

eZFSFileHandler::fileDeleteByWildcard ( wildcard) [static]

Delete files matching given wildcard.

Note that this method is faster than fileDeleteByRegex().

See also:
fileDeleteByRegex()

Definition at line 658 of file ezfsfilehandler.php.

Deletes a file that has been fetched before.

See also:
fetchUnique

In case of fetching from filesystem does nothing.

Definition at line 780 of file ezfsfilehandler.php.

eZFSFileHandler::fileExists ( path) [static]

Check if given file/dir exists.

Reimplemented in eZFS2FileHandler.

Definition at line 861 of file ezfsfilehandler.php.

eZFSFileHandler::fileFetch ( filePath)

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

In case of fetching from filesystem does nothing.

Definition at line 134 of file ezfsfilehandler.php.

Returns file contents.

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

Definition at line 228 of file ezfsfilehandler.php.

eZFSFileHandler::fileLinkCopy ( srcPath,
dstPath,
symLink 
) [static]

Create symbolic or hard link to file.

Definition at line 926 of file ezfsfilehandler.php.

eZFSFileHandler::fileMove ( srcPath,
dstPath 
) [static]

Move file.

Definition at line 941 of file ezfsfilehandler.php.

eZFSFileHandler::fileStore ( filePath,
scope = false,
delete = false,
datatype = false 
)

Store file.

In case of storing to filesystem does nothing.

Parameters:
string$filePathPath to the file being stored.
string$scopeMeans something like "file category". May be used to clean caches of a certain type.
string$deletetrue if the file should be deleted after storing.

Definition at line 173 of file ezfsfilehandler.php.

eZFSFileHandler::fileStoreContents ( filePath,
contents,
scope = false,
datatype = false 
) [static]

Store file contents.

Definition at line 184 of file ezfsfilehandler.php.

Reimplemented in eZFS2FileHandler.

Definition at line 1046 of file ezfsfilehandler.php.

eZFSFileHandler::isExpired ( expiry,
curtime,
ttl 
)

Calculates if the current file data is expired or not.

Parameters:
int$expiryTime when file is to be expired, a value of -1 will disable this check.
int$curtimeThe current time to check against.
int$ttlNumber of seconds the data can live, set to null to disable TTL.
Returns:
bool

Definition at line 454 of file ezfsfilehandler.php.

Referenced by eZFS2FileHandler\processCache(), and processCache().

static eZFSFileHandler::isFileExpired ( fname,
mtime,
expiry,
curtime,
ttl 
) [static]

Calculates if the file data is expired or not.

Parameters:
string$fnameName of file, available for easy debugging.
int$mtimeModification time of file, can be set to false if file does not exist.
int$expiryTime when file is to be expired, a value of -1 will disable this check.
int$curtimeThe current time to check against.
int$ttlNumber of seconds the data can live, set to null to disable TTL.
Returns:
bool

Definition at line 424 of file ezfsfilehandler.php.

Referenced by isExpired().

Load file meta information.

Parameters:
$forceIf true, file stats will be refreshed

Definition at line 113 of file ezfsfilehandler.php.

Referenced by delete(), eZFS2FileHandler\endCacheGeneration(), eZFSFileHandler(), and eZFS2FileHandler\processCache().

eZFSFileHandler::move ( dstPath)

Move file.

Definition at line 955 of file ezfsfilehandler.php.

Referenced by fileMove().

Returns file modification time.

Definition at line 582 of file ezfsfilehandler.php.

Returns file name.

Definition at line 594 of file ezfsfilehandler.php.

eZFSFileHandler::passthrough ( offset = 0,
length = false 
)

Outputs file contents to the browser Note: does not handle headers.

eZFile::downloadHeaders() can be used for this

Parameters:
int$offsetTransfer start offset
int$lengthTransfer length, in bytes

Definition at line 895 of file ezfsfilehandler.php.

eZFSFileHandler::processCache ( retrieveCallback,
generateCallback = null,
ttl = null,
expiry = null,
extraData = null 
)

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 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 $expiry and $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.

Reimplemented in eZFS2FileHandler.

Definition at line 302 of file ezfsfilehandler.php.

Referenced by processFile().

eZFSFileHandler::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().

Note:
Unlike processCache() this returns null if the file cannot be accessed.

Definition at line 544 of file ezfsfilehandler.php.

eZFSFileHandler::purge ( printCallback = false,
microsleep = false,
max = false,
expiry = false 
)

Purge local and remote file data for current file.

Reimplemented in eZFS2FileHandler.

Definition at line 801 of file ezfsfilehandler.php.

eZFS does not require binary purge.

Files are stored on plain FS and removed using FS functions

Since:
4.3
Deprecated:
Deprecated as of 4.5, use eZFSFileHandler::requiresPurge() instead.
Returns:
bool

Reimplemented in eZFS2FileHandler.

Definition at line 1029 of file ezfsfilehandler.php.

eZFS only stores data to FS and doesn't require/support clusterizing

Returns:
bool false

Reimplemented in eZFS2FileHandler.

Definition at line 1016 of file ezfsfilehandler.php.

eZFS does not require binary purge.

Files are stored on plain FS and removed using FS functions

Since:
4.5.0
Returns:
bool

Reimplemented in eZFS2FileHandler.

Definition at line 1041 of file ezfsfilehandler.php.

Returns file size.

Definition at line 570 of file ezfsfilehandler.php.

Starts cache generation for the current file.

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

Todo:
add timeout handling...
Returns:
mixed true if generation lock was granted, an integer matching the time before the current generation times out

Reimplemented in eZFS2FileHandler.

Definition at line 977 of file ezfsfilehandler.php.

Returns file metadata.

Definition at line 559 of file ezfsfilehandler.php.

Referenced by loadMetaData().

eZFSFileHandler::storeCache ( fileData,
storeCache = true 
) [private]

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().

Note:
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.

Reimplemented in eZFS2FileHandler.

Definition at line 472 of file ezfsfilehandler.php.

Referenced by processCache().

eZFSFileHandler::storeContents ( contents,
scope = false,
datatype = false,
storeLocally = false 
)

Store file contents to disk.

Parameters:
string$contentsBinary file data
string$datatypeNot used in the FS handler
string$scopeNot used in the FS handler
bool$storeLocallyNot used in the FS handler
Returns:
void

Definition at line 208 of file ezfsfilehandler.php.

Referenced by eZFS2FileHandler\storeCache(), and storeCache().


Member Data Documentation

eZFSFileHandler::$metaData = null

Definition at line 1051 of file ezfsfilehandler.php.

This should be defined in eZFS2FileHandler, but due to static members limitations in PHP < 5.3, it is declared here.

Definition at line 17 of file ezfsfilehandler.php.

Referenced by eZFS2FileHandler\exists(), and eZFS2FileHandler\fileExists().


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