FilesBackend
in package
Abstract class for a backend storage for the database-managed files
Table of Contents
Properties
- $backend_type : mixed
- Declare the backend type we're using
- $logging : bool|callable
Methods
- absUrl() : string
- Returns the absolute URL for a given file id, including domain.
- baseDir() : string
- Generate server files base directory path
- cleanupLocalCopy() : bool
- Remove a local copy of a file
- clearCacheResponse() : void
- Clear a cached file function response
- clearCaches() : void
- Clear all caches for a given file
- createLocalCopy() : string|null
- Create a copy of the file in a temporary directory.
- delete() : bool
- Delete a file
- deleteDir() : mixed
- Delete a directory
- exists() : bool
- Determine if a file exists
- getCacheKey() : string
- Get a repeatable and predictable rdb key for a file function response
- getCacheResponse() : mixed
- Get a cached file function response
- getConfig() : array<string|int, mixed>
- Get the config settings for the current backend
- getName() : string
- Get the name for the current backend
- getSettings() : array<string|int, mixed>
- Get the AWS config merge settings.
- getStream() : StreamInterface|null
- Get a PSR stream for a file.
- getString() : string|false
- Returns file content as a string. Basically the same as file_get_contents
- getTransformFolderPrefix() : string
- getType() : string
- Get the 'type' key for the current backend
- glob() : array<string|int, mixed>
- Returns all files which match the specified mask.
- imageSize() : array<string|int, mixed>|false
- Returns the size of an image, or false on failure.
- mkDir() : mixed
- Create an empty directory
- moveFile() : bool
- Moves a file within the backend context.
- moveUpload() : bool
- Moves an uploaded file into the repository.
- mtime() : int|false
- Get the modified time, in unix timestamp format, of the specified file
- putExisting() : bool
- Saves file content from an existing (local) file
- putStream() : bool
- Saves file content from a stream. Basically just fopen/stream_copy_to_stream/fclose
- putString() : bool
- Saves file content as a string. Basically the same as file_put_contents
- readfile() : int|false
- This is the equivalent of the php readfile function
- relUrl() : string
- Returns the relative URL for a given file.
- resizeUrl() : string
- Returns the relative URL for a dynamically resized image.
- setCacheResponse() : void
- Set a cached file function response
- setLogging() : void
- Override the logging.
- size() : int|false
- Get the size, in bytes, of the specified file
- touch() : bool
- Sets access and modification time of file
- log() : void
- Log a mesasge or exception.
Properties
$backend_type
Declare the backend type we're using
protected
mixed
$backend_type
= null
$logging
protected
bool|callable
$logging
= !IN_PRODUCTION
Methods
absUrl()
Returns the absolute URL for a given file id, including domain.
public
abstract absUrl(string $filename) : string
Parameters
- $filename : string
Return values
string —e.g. http://example.com/files/filename.jpg
baseDir()
Generate server files base directory path
public
abstract baseDir() : string
Return values
stringcleanupLocalCopy()
Remove a local copy of a file
public
cleanupLocalCopy(string $temp_filename) : bool
Parameters
- $temp_filename : string
-
The filename returned by createLocalCopy
Return values
boolclearCacheResponse()
Clear a cached file function response
public
clearCacheResponse(string $function, string $filename) : void
Parameters
- $function : string
- $filename : string
clearCaches()
Clear all caches for a given file
public
clearCaches(string $filename) : void
Parameters
- $filename : string
createLocalCopy()
Create a copy of the file in a temporary directory.
public
abstract createLocalCopy(string $filename) : string|null
Don't forget to File::destroy_local_copy($temp_filename) when you're done!
Parameters
- $filename : string
-
The file to copy into a temporary location
Return values
string|null —Temp filename or NULL on error
delete()
Delete a file
public
abstract delete(string $filename) : bool
Parameters
- $filename : string
Return values
booldeleteDir()
Delete a directory
public
abstract deleteDir(mixed $directory) : mixed
Parameters
- $directory : mixed
exists()
Determine if a file exists
public
abstract exists(string $filename) : bool
Parameters
- $filename : string
-
The file to check for
Return values
bool —Returns TRUE if the file exists, and FALSE if it does not
getCacheKey()
Get a repeatable and predictable rdb key for a file function response
public
getCacheKey(string $function, string $filename) : string
Parameters
- $function : string
- $filename : string
Return values
stringgetCacheResponse()
Get a cached file function response
public
getCacheResponse(string $function, string $filename) : mixed
Parameters
- $function : string
- $filename : string
Return values
mixed —Cache val or null if empty
getConfig()
Get the config settings for the current backend
public
getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>getName()
Get the name for the current backend
public
getName() : string
Return values
stringgetSettings()
Get the AWS config merge settings.
public
getSettings() : array<string|int, mixed>
Return values
array<string|int, mixed>getStream()
Get a PSR stream for a file.
public
abstract getStream(string $filename) : StreamInterface|null
Parameters
- $filename : string
Return values
StreamInterface|nullgetString()
Returns file content as a string. Basically the same as file_get_contents
public
abstract getString(string $filename) : string|false
Parameters
- $filename : string
Return values
string|falsegetTransformFolderPrefix()
public
getTransformFolderPrefix() : string
Tags
Return values
stringgetType()
Get the 'type' key for the current backend
public
getType() : string
Return values
stringglob()
Returns all files which match the specified mask.
public
abstract glob(string $mask[, mixed $depth = 0 ]) : array<string|int, mixed>
I have a feeling this returns other sizes (e.g. .small) as well - which may not be ideal.
Parameters
- $mask : string
-
The search mask / string
- $depth : mixed = 0
Return values
array<string|int, mixed> —An array of results from the lookup
imageSize()
Returns the size of an image, or false on failure.
public
abstract imageSize(string $filename) : array<string|int, mixed>|false
Output format is the same as getimagesize, but will be at a minimum: [0] => width, [1] => height, [2] => type
Parameters
- $filename : string
Return values
array<string|int, mixed>|false —depending if found
mkDir()
Create an empty directory
public
abstract mkDir(mixed $directory) : mixed
Parameters
- $directory : mixed
moveFile()
Moves a file within the backend context.
public
abstract moveFile(string $src, string $dest) : bool
Parameters
- $src : string
-
The source filename to move
- $dest : string
-
The target filename to move it to
Return values
bool —Returns TRUE on success, FALSE on failure.
moveUpload()
Moves an uploaded file into the repository.
public
abstract moveUpload(string $src, string $filename) : bool
Parameters
- $src : string
-
The source file to move
- $filename : string
-
The filename to move it to
Return values
bool —Returns TRUE on success, FALSE on failure.
mtime()
Get the modified time, in unix timestamp format, of the specified file
public
abstract mtime(string $filename) : int|false
Parameters
- $filename : string
Return values
int|false —The modified file timestamp
putExisting()
Saves file content from an existing (local) file
public
abstract putExisting(string $filename, string $existing) : bool
Parameters
- $filename : string
- $existing : string
Return values
boolputStream()
Saves file content from a stream. Basically just fopen/stream_copy_to_stream/fclose
public
abstract putStream(string $filename, resource|StreamInterface $stream) : bool
Parameters
- $filename : string
- $stream : resource|StreamInterface
Return values
boolputString()
Saves file content as a string. Basically the same as file_put_contents
public
abstract putString(string $filename, string $content) : bool
Parameters
- $filename : string
- $content : string
Return values
boolreadfile()
This is the equivalent of the php readfile function
public
abstract readfile(string $filename) : int|false
Parameters
- $filename : string
Return values
int|falserelUrl()
Returns the relative URL for a given file.
public
abstract relUrl(string $filename) : string
Use for content areas.
Parameters
- $filename : string
Return values
string —e.g. files/filename.jpg
resizeUrl()
Returns the relative URL for a dynamically resized image.
public
resizeUrl(string $filename, string $size) : string
Size formatting is as per File::parseSizeString, e.g. c400x300
Parameters
- $filename : string
- $size : string
-
A code as per File::parseSizeString
Return values
string —HTML-safe relative URL, e.g. file/resize/c400x300/123_example.jpg
setCacheResponse()
Set a cached file function response
public
setCacheResponse(string $function, string $filename, mixed $response[, int $ttl = null ]) : void
Parameters
- $function : string
- $filename : string
- $response : mixed
- $ttl : int = null
-
Number of seconds to hold cache for. Defaults to one day
setLogging()
Override the logging.
public
setLogging(bool|callable $logging) : void
By default logging is disabled in production environments. In non-production environments exceptions are logged to the error log.
Provide a callable to log other messages.
Parameters
- $logging : bool|callable
size()
Get the size, in bytes, of the specified file
public
abstract size(string $filename) : int|false
Parameters
- $filename : string
Return values
int|falsetouch()
Sets access and modification time of file
public
abstract touch(string $filename) : bool
Parameters
- $filename : string
Return values
boollog()
Log a mesasge or exception.
protected
log(mixed $message) : void
Parameters
- $message : mixed