Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | List of all members
eZFSFileHandler Class Reference
Inheritance diagram for eZFSFileHandler:

## Public Member Functions
| __construct ( $filePath=false)
| loadMetaData ( $force=false)
| fileFetch ( $filePath)
| fetch ( $noLocalCache=false)
| fetchUnique ()
| fileStore ( $filePath, $scope=false, $delete=false, $datatype=false)
| storeContents ( $contents, $scope=false, $datatype=false, $storeLocally=false)
| fileFetchContents ( $filePath)
| fetchContents ()
| processCache ( $retrieveCallback, $generateCallback=null, $ttl=null, $expiry=null, $extraData=null)
| isExpired ( $expiry, $curtime, $ttl)
| processFile ( $callback, $expiry=false, $extraData=null)
| stat ()
| size ()
| dataType ()
| mtime ()
| name ()
| fileDeleteLocal ( $path)
| deleteLocal ()
| purge ( $printCallback=false, $microsleep=false, $max=false, $expiry=false)
| exists ()
| passthrough ( $offset=0, $length=false)
| move ( $dstPath)
| startCacheGeneration ()
| endCacheGeneration ( $rename=true)
| abortCacheGeneration ()
| checkCacheGenerationTimeout ()
| requiresClusterizing ()
| requiresPurge ()
| hasStaleCacheSupport ()
| getFileList ($scopes=false, $excludeScopes=false)
| isDBFileExpired ($expiry, $curtime, $ttl)
| isLocalFileExpired ($expiry, $curtime, $ttl)
| applyServerUri ( $filePath)

## Static Public Member Functions
| fileStoreContents ( $filePath, $contents, $scope=false, $datatype=false)
static | isFileExpired ( $fname, $mtime, $expiry, $curtime, $ttl)
| fileDeleteByWildcard ( $wildcard)
| fileDeleteByDirList ( $dirList, $commonPath, $commonSuffix)
| fileDelete ( $path, $fnamePart=false)
| delete ()
| fileExists ( $path)
| fileCopy ( $srcPath, $dstPath)
| fileLinkCopy ( $srcPath, $dstPath, $symLink)
| fileMove ( $srcPath, $dstPath)

## Public Attributes
const | EXPIRY_TIMESTAMP = 233366400
| $metaData = null
| $filePath
| $Mutex
| $lifetime

## Private Member Functions
| _exclusiveLock ( $fname=false)
| _freeExclusiveLock ( $fname=false)
& | _mutex ()
| storeCache ( $fileData, $storeCache=true)

## Detailed Description

Definition at line 11 of file ezfsfilehandler.php.

## Constructor & Destructor Documentation

## ◆ __construct()

eZFSFileHandler::__construct | ( |  | $filePath = `false` | ) |

Constructor.

Parameters

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

Definition at line 20 of file ezfsfilehandler.php.

References $filePath, loadMetaData(), and eZDebugSetting\writeDebug().

## Member Function Documentation

## ◆ _exclusiveLock()

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

  $fname | Name of the calling code (usually function name).

Definition at line 40 of file ezfsfilehandler.php.

References _mutex(), and eZDebug\writeWarning().

Referenced by processCache().

## ◆ _freeExclusiveLock()

eZFSFileHandler::_freeExclusiveLock | ( |  | $fname = `false` | ) |
| private

Frees the current exclusive lock in use.

Parameters

  $fname | Name of the calling code (usually function name).

Definition at line 85 of file ezfsfilehandler.php.

References _mutex().

Referenced by abortCacheGeneration(), processCache(), and storeCache().

## ◆ _mutex()

& eZFSFileHandler::_mutex | ( |  | ) |
| private

Returns the mutex object for the current file.

Definition at line 95 of file ezfsfilehandler.php.

References $Mutex.

Referenced by _exclusiveLock(), and _freeExclusiveLock().

## ◆ abortCacheGeneration()

eZFSFileHandler::abortCacheGeneration | ( |  | ) |

Aborts the current cache generation process.

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

Definition at line 963 of file ezfsfilehandler.php.

References _freeExclusiveLock().

Referenced by storeCache().

## ◆ applyServerUri()

eZFSFileHandler::applyServerUri | ( |  | $filePath | ) |

No transformation is required since files are served from the same host

Definition at line 1025 of file ezfsfilehandler.php.

References $filePath.

## ◆ checkCacheGenerationTimeout()

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

Definition at line 975 of file ezfsfilehandler.php.

## ◆ dataType()

eZFSFileHandler::dataType | ( |  | ) |

Returns file mime-type / content-type.

Returns
  string|null

Definition at line 583 of file ezfsfilehandler.php.

References eZDebugSetting\writeDebug().

## ◆ delete()

eZFSFileHandler::delete | ( |  | ) |
| static

Deletes specified file/directory.

If a directory specified it is deleted recursively.

Definition at line 713 of file ezfsfilehandler.php.

References $filePath, eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZClusterFileHandler\cleanupEmptyDirectories(), eZFileHandler\instance(), loadMetaData(), eZDir\recursiveDelete(), eZDebugSetting\writeDebug(), and eZDebug\writeError().

## ◆ deleteLocal()

eZFSFileHandler::deleteLocal | ( |  | ) |

Deletes a file that has been fetched before.

In case of fetching from filesystem does nothing.

Definition at line 759 of file ezfsfilehandler.php.

References $filePath, and eZDebugSetting\writeDebug().

## ◆ endCacheGeneration()

eZFSFileHandler::endCacheGeneration | ( |  | $rename = `true` | ) |

Ends the cache generation started by startCacheGeneration().

Definition at line 952 of file ezfsfilehandler.php.

## ◆ exists()

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

Definition at line 847 of file ezfsfilehandler.php.

References $filePath, and eZDebugSetting\writeDebug().

## ◆ fetch()

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 141 of file ezfsfilehandler.php.

References $filePath, and eZDebugSetting\writeDebug().

## ◆ fetchContents()

eZFSFileHandler::fetchContents | ( |  | ) |

Returns file contents.

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

Definition at line 241 of file ezfsfilehandler.php.

References $filePath, eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), and eZDebugSetting\writeDebug().

## ◆ fetchUnique()

eZFSFileHandler::fetchUnique | ( |  | ) |

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 154 of file ezfsfilehandler.php.

References $filePath, and eZDebugSetting\writeDebug().

## ◆ fileCopy()

eZFSFileHandler::fileCopy | ( |  | $srcPath,
|  |  | $dstPath
| ) |  |
| static

Copy file.

Definition at line 878 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFileHandler\copy(), and eZDebugSetting\writeDebug().

## ◆ fileDelete()

eZFSFileHandler::fileDelete | ( |  | $path,
|  |  | $fnamePart = `false`
| ) |  |
| static

Definition at line 663 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFileHandler\instance(), eZDir\recursiveDelete(), eZDebugSetting\writeDebug(), and eZDebug\writeError().

## ◆ fileDeleteByDirList()

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

Definition at line 641 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZSys\globBrace(), and eZDebugSetting\writeDebug().

## ◆ fileDeleteByWildcard()

eZFSFileHandler::fileDeleteByWildcard | ( |  | $wildcard | ) |
| static

Delete files matching given wildcard.

Definition at line 620 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZSys\globBrace(), and eZDebugSetting\writeDebug().

## ◆ fileDeleteLocal()

eZFSFileHandler::fileDeleteLocal | ( |  | $path | ) |

Deletes a file that has been fetched before.

See also
  fetchUnique

In case of fetching from filesystem does nothing.

Definition at line 747 of file ezfsfilehandler.php.

References eZDebugSetting\writeDebug().

## ◆ fileExists()

eZFSFileHandler::fileExists | ( |  | $path | ) |
| static

Check if given file/dir exists.

Definition at line 828 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), and eZDebugSetting\writeDebug().

## ◆ fileFetch()

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 130 of file ezfsfilehandler.php.

References $filePath, and eZDebugSetting\writeDebug().

## ◆ fileFetchContents()

eZFSFileHandler::fileFetchContents | ( |  | $filePath | ) |

Returns file contents.

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

Definition at line 224 of file ezfsfilehandler.php.

References $filePath, eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), and eZDebugSetting\writeDebug().

## ◆ fileLinkCopy()

eZFSFileHandler::fileLinkCopy | ( |  | $srcPath,
|  |  | $dstPath,
|  |  | $symLink
| ) |  |
| static

Create symbolic or hard link to file.

Definition at line 893 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFileHandler\linkCopy(), and eZDebugSetting\writeDebug().

## ◆ fileMove()

eZFSFileHandler::fileMove | ( |  | $srcPath,
|  |  | $dstPath
| ) |  |
| static

Move file.

Definition at line 908 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFile\rename(), and eZDebugSetting\writeDebug().

## ◆ fileStore()

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

Store file.

In case of storing to filesystem does nothing.

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.
  string | $delete | true if the file should be deleted after storing.

Definition at line 169 of file ezfsfilehandler.php.

References eZDebugSetting\writeDebug().

## ◆ fileStoreContents()

eZFSFileHandler::fileStoreContents | ( |  | $filePath,
|  |  | $contents,
|  |  | $scope = `false`,
|  |  | $datatype = `false`
| ) |  |
| static

Store file contents.

Definition at line 180 of file ezfsfilehandler.php.

References $filePath, eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFile\create(), and eZDebugSetting\writeDebug().

## ◆ getFileList()

eZFSFileHandler::getFileList | ( |  | $scopes = `false`,
|  |  | $excludeScopes = `false`
| ) |  |

Definition at line 1007 of file ezfsfilehandler.php.

## ◆ hasStaleCacheSupport()

eZFSFileHandler::hasStaleCacheSupport | ( |  | ) |

Definition at line 1002 of file ezfsfilehandler.php.

## ◆ isDBFileExpired()

eZFSFileHandler::isDBFileExpired | ( |  | $expiry,
|  |  | $curtime,
|  |  | $ttl
| ) |  |

Definition at line 1012 of file ezfsfilehandler.php.

References isFileExpired().

## ◆ isExpired()

eZFSFileHandler::isExpired | ( |  | $expiry,
|  |  | $curtime,
|  |  | $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.

Returns
  bool

Definition at line 456 of file ezfsfilehandler.php.

References isFileExpired().

Referenced by processCache().

## ◆ isFileExpired()

static eZFSFileHandler::isFileExpired | ( |  | $fname,
|  |  | $mtime,
|  |  | $expiry,
|  |  | $curtime,
|  |  | $ttl
| ) |  |
| static

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.

Returns
  bool

Definition at line 426 of file ezfsfilehandler.php.

Referenced by isDBFileExpired(), isExpired(), and isLocalFileExpired().

## ◆ isLocalFileExpired()

eZFSFileHandler::isLocalFileExpired | ( |  | $expiry,
|  |  | $curtime,
|  |  | $ttl
| ) |  |

Definition at line 1017 of file ezfsfilehandler.php.

References isFileExpired().

## ◆ loadMetaData()

eZFSFileHandler::loadMetaData | ( |  | $force = `false` | ) |

Load file meta information.

Parameters

  $force | If true, file stats will be refreshed

Definition at line 109 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), stat(), and eZDebugSetting\writeDebug().

Referenced by __construct(), and delete().

## ◆ move()

eZFSFileHandler::move | ( |  | $dstPath | ) |

Move file.

Definition at line 922 of file ezfsfilehandler.php.

References $filePath, eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFileHandler\move(), and eZDebugSetting\writeDebug().

## ◆ mtime()

eZFSFileHandler::mtime | ( |  | ) |

Returns file modification time.

Definition at line 596 of file ezfsfilehandler.php.

References eZDebugSetting\writeDebug().

## ◆ name()

eZFSFileHandler::name | ( |  | ) |

Returns file name.

Definition at line 608 of file ezfsfilehandler.php.

References $filePath, and eZDebugSetting\writeDebug().

## ◆ passthrough()

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 | $offset | Transfer start offset
  int | $length | Transfer length, in bytes

Definition at line 862 of file ezfsfilehandler.php.

References eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFile\downloadContent(), and eZDebugSetting\writeDebug().

## ◆ processCache()

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.

Definition at line 298 of file ezfsfilehandler.php.

References $filePath, _exclusiveLock(), _freeExclusiveLock(), isExpired(), storeCache(), eZDebugSetting\writeDebug(), and eZDebug\writeError().

Referenced by processFile().

## ◆ 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 546 of file ezfsfilehandler.php.

References processCache().

## ◆ purge()

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

Purge local and remote file data for current file.

Definition at line 768 of file ezfsfilehandler.php.

References $filePath, and eZClusterFileHandler\cleanupEmptyDirectories().

## ◆ requiresClusterizing()

eZFSFileHandler::requiresClusterizing | ( |  | ) |

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

Returns
  bool false

Definition at line 985 of file ezfsfilehandler.php.

## ◆ requiresPurge()

eZFSFileHandler::requiresPurge | ( |  | ) |

eZFS does not require binary purge. Files are stored on plain FS and removed using FS functions

Since
  4.5.0

Returns
  bool

Definition at line 997 of file ezfsfilehandler.php.

## ◆ size()

eZFSFileHandler::size | ( |  | ) |

Returns file size.

Definition at line 572 of file ezfsfilehandler.php.

References eZDebugSetting\writeDebug().

## ◆ startCacheGeneration()

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

Definition at line 944 of file ezfsfilehandler.php.

## ◆ stat()

eZFSFileHandler::stat | ( |  | ) |

Returns file metadata.

Definition at line 561 of file ezfsfilehandler.php.

References $metaData, and eZDebugSetting\writeDebug().

Referenced by loadMetaData().

## ◆ storeCache()

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.

Definition at line 474 of file ezfsfilehandler.php.

References $filePath, _freeExclusiveLock(), abortCacheGeneration(), storeContents(), and eZDebug\writeError().

Referenced by processCache().

## ◆ storeContents()

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

Store file contents to disk

Parameters

  string | $contents | Binary file data
  string | $datatype | Not used in the FS handler
  string | $scope | Not used in the FS handler
  bool | $storeLocally | Not used in the FS handler

Returns
  void

Definition at line 204 of file ezfsfilehandler.php.

References $filePath, eZDebug\accumulatorStart(), eZDebug\accumulatorStop(), eZFile\create(), and eZDebugSetting\writeDebug().

Referenced by storeCache().

## Member Data Documentation

## ◆ $filePath

eZFSFileHandler::$filePath

Definition at line 1031 of file ezfsfilehandler.php.

Referenced by __construct(), applyServerUri(), delete(), deleteLocal(), exists(), fetch(), fetchContents(), fetchUnique(), fileFetch(), fileFetchContents(), fileStoreContents(), move(), name(), processCache(), purge(), storeCache(), and storeContents().

## ◆ $lifetime

eZFSFileHandler::$lifetime

Definition at line 1033 of file ezfsfilehandler.php.

## ◆ $metaData

eZFSFileHandler::$metaData = null

Definition at line 1030 of file ezfsfilehandler.php.

Referenced by stat().

## ◆ $Mutex

eZFSFileHandler::$Mutex

Definition at line 1032 of file ezfsfilehandler.php.

Referenced by _mutex().

## ◆ EXPIRY_TIMESTAMP

const eZFSFileHandler::EXPIRY_TIMESTAMP = 233366400

Definition at line 13 of file ezfsfilehandler.php.

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

- ezfsfilehandler.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.