FileStorage
in package
Table of Contents
Properties
- $defaultFileExtension : string
- $generator : SlugGenerator
- $relativeStoragePath : string
- $rootPath : string
Methods
- __construct() : mixed
- FileCache constructor.
- get() : string|null
- Get the storage path for given identifier. Caution: Identifier will be normalized!
- set() : string
- Persist a file in the file storage, uniquely references by an identifier. Caution: identifier will be normalized!
- createAbsoluteFilePath() : string
- Return the absoulte path to the file.
- createFilename() : string
- Create the filename out of key and file extension.
- createRelativeFilePath() : string
- Return the relative path to the file.
- normalizeKey() : string
- Normalize the key.
Properties
$defaultFileExtension
private
string
$defaultFileExtension
$generator
private
SlugGenerator
$generator
$relativeStoragePath
private
string
$relativeStoragePath
$rootPath
private
string
$rootPath
Methods
__construct()
FileCache constructor.
public
__construct(string $rootPath, string $storagePath[, string $defaultFileExtension = '' ]) : mixed
Parameters
- $rootPath : string
-
The project root path
- $storagePath : string
-
The storage path relative to the project root path
- $defaultFileExtension : string = ''
-
The default file extension of the files to store
get()
Get the storage path for given identifier. Caution: Identifier will be normalized!
public
get(string $key[, string|null $default = null ][, array<string|int, mixed> $options = [] ]) : string|null
Options:
- fileExtension: (string) Override the default file extension.
Parameters
- $key : string
-
the key for the item in store
- $default : string|null = null
-
Default value to return if key does not exist
- $options : array<string|int, mixed> = []
-
Additional options
Tags
Return values
string|null —return the path of the item from the storage, or $default if not found
set()
Persist a file in the file storage, uniquely references by an identifier. Caution: identifier will be normalized!
public
set(string $identifier, callable|string $value[, array<string|int, mixed> $options = [] ]) : string
Value:
- callable: Gets a FileStorageCallback object as parameter and must return bool (true on success, false otherwise).
- string: Will be directly written to the file.
Options:
- fileExtension: (string) Override the default file extension.
Parameters
- $identifier : string
-
the key of the item to store
- $value : callable|string
-
The value of the item to store. Must be a callable or string.
- $options : array<string|int, mixed> = []
Tags
Return values
string —return the path of the item from the storage
createAbsoluteFilePath()
Return the absoulte path to the file.
protected
createAbsoluteFilePath(string $filename) : string
Parameters
- $filename : string
Return values
stringcreateFilename()
Create the filename out of key and file extension.
protected
createFilename(string $key, array<string|int, mixed> $options) : string
Parameters
- $key : string
- $options : array<string|int, mixed>
Return values
stringcreateRelativeFilePath()
Return the relative path to the file.
protected
createRelativeFilePath(string $filename) : string
Parameters
- $filename : string
Return values
stringnormalizeKey()
Normalize the key.
protected
normalizeKey(string $key) : string
Parameters
- $key : string