eZPublish  4.7
eZFS2FileHandler Class Reference
+ Inheritance diagram for eZFS2FileHandler:
+ Collaboration diagram for eZFS2FileHandler:

Public Member Functions

 __construct ($filePath=false)
 
 __get ($propertyName)
 Magic getter. More...
 
 abortCacheGeneration ()
 Aborts the current cache generation process. More...
 
 checkCacheGenerationTimeout ()
 Checks if the .generating file was changed, which would mean that generation timed out. More...
 
 deleteLocal ()
 Deletes a file that has been fetched before. More...
 
 endCacheGeneration ($rename=true)
 Ends the cache generation started by startCacheGeneration(). More...
 
 exists ()
 Check if given file/dir exists. More...
 
 fileDelete ($path, $fnamePart=false)
 Deletes the file(s) or directory matching $path and $fnamePart if given. More...
 
 hasStaleCacheSupport ()
 
 processCache ($retrieveCallback, $generateCallback=null, $ttl=null, $expiry=null, $extraData=null)
 Creates a single transaction out of the typical file operations for accessing caches. More...
 
 purge ($printCallback=false, $microsleep=false, $max=false, $expiry=false)
 Purge local and remote file data for current file. More...
 
 requiresBinaryPurge ()
 eZFS2 doesn't require purge as it already purges files in realtime (FS based) More...
 
 requiresClusterizing ()
 eZFS2 doesn't require clusterizing, as it only uses the filesystem More...
 
 requiresPurge ()
 eZFS2 doesn't require purge as it already purges files in realtime (FS based) More...
 
 startCacheGeneration ()
 Starts cache generation for the current file. More...
 
 storeCache ($fileData, $storeCache=true)
 Stores the data in $fileData to the remote and local file and commits the transaction. More...
 
- Public Member Functions inherited from eZFSFileHandler
 abortCacheGeneration ()
 Aborts the current cache generation process. More...
 
 checkCacheGenerationTimeout ()
 Checks if the .generating file was changed, which would mean that generation timed out. More...
 
 deleteLocal ()
 Deletes a file that has been fetched before. More...
 
 endCacheGeneration ()
 Ends the cache generation started by startCacheGeneration(). More...
 
 exists ()
 Check if given file/dir exists. More...
 
 eZFSFileHandler ($filePath=false)
 Constructor. More...
 
 fetch ($noLocalCache=false)
 Fetches file from db and saves it in FS under the same name. More...
 
 fetchContents ()
 Returns file contents. More...
 
 fetchUnique ()
 Fetches file from db and saves it in FS under unique name. More...
 
 fileDeleteLocal ($path)
 Deletes a file that has been fetched before. More...
 
 fileFetch ($filePath)
 Fetches file from db and saves it in FS under the same name. More...
 
 fileFetchContents ($filePath)
 Returns file contents. More...
 
 fileStore ($filePath, $scope=false, $delete=false, $datatype=false)
 Store file. More...
 
 hasStaleCacheSupport ()
 
 isExpired ($expiry, $curtime, $ttl)
 Calculates if the current file data is expired or not. More...
 
 loadMetaData ($force=false)
 
 move ($dstPath)
 Move file. More...
 
 mtime ()
 Returns file modification time. More...
 
 name ()
 Returns file name. More...
 
 passthrough ($offset=0, $length=false)
 Outputs file contents to the browser Note: does not handle headers. More...
 
 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. More...
 
 requiresClusterizing ()
 eZFS only stores data to FS and doesn't require/support clusterizing More...
 
 requiresPurge ()
 eZFS does not require binary purge. More...
 
 size ()
 Returns file size. More...
 
 startCacheGeneration ()
 Starts cache generation for the current file. More...
 
 stat ()
 Returns file metadata. More...
 
 storeContents ($contents, $scope=false, $datatype=false, $storeLocally=false)
 Store file contents to disk. More...
 

Static Public Member Functions

 delete ()
 Deletes specified file/directory. More...
 
 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. More...
 
- Static Public Member Functions inherited from eZFSFileHandler
 delete ()
 Deletes specified file/directory. More...
 
 fileCopy ($srcPath, $dstPath)
 Copy file. More...
 
 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. More...
 
 fileDeleteByRegex ($dir, $fileRegex)
 Delete files matching regex $fileRegex under directory $dir. More...
 
 fileDeleteByWildcard ($wildcard)
 Delete files matching given wildcard. More...
 
 fileExists ($path)
 Check if given file/dir exists. More...
 
 fileLinkCopy ($srcPath, $dstPath, $symLink)
 Create symbolic or hard link to file. More...
 
 fileMove ($srcPath, $dstPath)
 Move file. More...
 
 fileStoreContents ($filePath, $contents, $scope=false, $datatype=false)
 Store file contents. More...
 
static isFileExpired ($fname, $mtime, $expiry, $curtime, $ttl)
 Calculates if the file data is expired or not. More...
 

Public Attributes

 $realFilePath = null
 holds the real file path. More...
 
- Public Attributes inherited from eZFSFileHandler
 $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. More...
 

Protected Attributes

 $generationStartTimestamp = false
 
 $generationTimeout
 
 $internalCacheType = null
 
 $nonExistantStaleCacheHandling
 Holds the preferences used when stale cache is activated and no expired file is available. More...
 
 $remainingCacheGenerationTime = false
 
 $useStaleCache = false
 

Private Member Functions

 _cacheType ()
 Determines the cache type based on the path. More...
 
 remainingCacheGenerationTime ($filePath)
 Returns the remaining time, in seconds, before the generating file times out. More...
 

Static Private Member Functions

static _expire ($path)
 Expire the given file. More...
 
static _recursiveExpire ($directory)
 Expires all files in a directory. More...
 

Constructor & Destructor Documentation

eZFS2FileHandler::__construct (   $filePath = false)

Member Function Documentation

eZFS2FileHandler::__get (   $propertyName)

Magic getter.

eZFS2FileHandler::_cacheType ( )
private

Determines the cache type based on the path.

Returns
string viewcache, cacheblock or misc

Referenced by __get().

static eZFS2FileHandler::_expire (   $path)
staticprivate

Expire the given file.

Parameters
string$pathPath of the file to expire
Returns
bool
static eZFS2FileHandler::_recursiveExpire (   $directory)
staticprivate

Expires all files in a directory.

Parameters
string$directory
Returns
void
eZFS2FileHandler::abortCacheGeneration ( )

Aborts the current cache generation process.

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

Referenced by storeCache().

eZFS2FileHandler::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

Referenced by storeCache().

eZFS2FileHandler::delete ( )
static

Deletes specified file/directory.

If a directory specified it is deleted recursively.

eZFS2FileHandler::deleteLocal ( )

Deletes a file that has been fetched before.

In case of fetching from filesystem does nothing.

eZFS2FileHandler::endCacheGeneration (   $rename = true)

Ends the cache generation started by startCacheGeneration().

If $rename is set to true (default), the .generating file is renamed and overwrites the real file. If set to false, the .generating file is removed, and the real file made available.

True should be used when actual data is stored in the standard file and not the .generating one, for instance when using image alias generation.

Parameters
bool$renameRename (true) or delete (false) the generating file
Returns
bool
eZFS2FileHandler::exists ( )

Check if given file/dir exists.

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

Referenced by processCache().

eZFS2FileHandler::fileDelete (   $path,
  $fnamePart = false 
)

Deletes the file(s) or directory matching $path and $fnamePart if given.

Parameters
$pathpath of the file to delete
$fnamePartpath of the file to delete
eZFS2FileHandler::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()
eZFS2FileHandler::hasStaleCacheSupport ( )
eZFS2FileHandler::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.

Parameters
mixed$retrieveCallback
mixed$generateCallback
int$ttl
int$expiry
array$extraData
eZFS2FileHandler::purge (   $printCallback = false,
  $microsleep = false,
  $max = false,
  $expiry = false 
)

Purge local and remote file data for current file.

eZFS2FileHandler::remainingCacheGenerationTime (   $filePath)
private

Returns the remaining time, in seconds, before the generating file times out.

Parameters
string$filePath
Returns
int Remaining generation seconds. A negative value indicates a timeout.

Referenced by abortCacheGeneration(), endCacheGeneration(), processCache(), and startCacheGeneration().

eZFS2FileHandler::requiresBinaryPurge ( )

eZFS2 doesn't require purge as it already purges files in realtime (FS based)

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

eZFS2 doesn't require clusterizing, as it only uses the filesystem

Returns
bool
eZFS2FileHandler::requiresPurge ( )

eZFS2 doesn't require purge as it already purges files in realtime (FS based)

Since
4.5.0
Returns
bool
eZFS2FileHandler::startCacheGeneration ( )

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

Referenced by processCache().

eZFS2FileHandler::storeCache (   $fileData,
  $storeCache = true 
)

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.

Referenced by processCache().

Member Data Documentation

eZFS2FileHandler::$generationStartTimestamp = false
protected
eZFS2FileHandler::$generationTimeout
protected
eZFS2FileHandler::$internalCacheType = null
protected

Referenced by __get().

eZFS2FileHandler::$nonExistantStaleCacheHandling
protected

Holds the preferences used when stale cache is activated and no expired file is available.

This is loaded from file.ini, ClusteringSettings.NonExistantStaleCacheHandling

eZFS2FileHandler::$realFilePath = null

holds the real file path.

This is only used when we are generating a cache file, in which case $filePath holds the generating cache file name, and $realFilePath holds the real name

Referenced by abortCacheGeneration(), and endCacheGeneration().

eZFS2FileHandler::$remainingCacheGenerationTime = false
protected
eZFS2FileHandler::$useStaleCache = false
protected

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