Horde_Vfs_SqlFile
extends Horde_Vfs_File
in package
Horde_Vfs:: implementation using PHP's PEAR database abstraction layer and local file system for file storage.
Required values for $params:
db - (DB) The DB object. vfsroot - (string) The root directory of where the files should be actually stored.
Optional values:
table - (string) The name of the vfs table in 'database'. Defaults to 'horde_vfs'.
The table structure for the VFS can be found in data/vfs.sql.
Tags
Table of Contents
- FILE = 1
- FOLDER = 2
- $_credentials : array<string|int, mixed>
- List of additional credentials required for this VFS backend (example: For FTP, we need a username and password to log in to the server with).
- $_db : DB
- Handle for the current database connection.
- $_features : array<string|int, mixed>
- List of features that the VFS driver supports.
- $_params : array<string|int, mixed>
- Hash containing connection parameters.
- $_permissions : array<string|int, mixed>
- List of permissions and if they can be changed in this VFS backend.
- $_vfsSize : int
- The current size, in bytes, of the VFS tree.
- __construct() : mixed
- Constructor.
- autocreatePath() : mixed
- Automatically creates any necessary parent directories in the specified $path.
- changePermissions() : mixed
- Changes permissions for an item on the VFS.
- checkCredentials() : mixed
- Checks the credentials that we have by calling _connect(), to see if there is a valid login.
- copy() : mixed
- Copies a file through the backend.
- createFolder() : mixed
- Creates a folder on the VFS.
- delete() : mixed
- Alias to deleteFile()
- deleteFile() : mixed
- Delete a file from the VFS.
- deleteFolder() : mixed
- Delete a folder from the VFS.
- emptyFolder() : mixed
- Recursively remove all files and subfolders from the given folder.
- exists() : bool
- Returns if a given file or folder exists in a folder.
- getCurrentDirectory() : string
- Returns the current working directory of the VFS backend.
- getFolderSize() : int
- Returns the size of a folder.
- getModifiablePermissions() : array<string|int, mixed>
- Returns an array specifying what permissions are changeable for this VFS implementation.
- getParam() : mixed
- Returns configuration parameters.
- getQuota() : mixed
- Get quota information (used/allocated), in bytes.
- getRequiredCredentials() : array<string|int, mixed>
- Returns the list of additional credentials required, if any.
- getVFSSize() : int
- Returns the size of the VFS item.
- hasFeature() : bool
- Returns whether the drivers supports a certain feature.
- isFolder() : bool
- Checks if a given item is a folder.
- listFolder() : array<string|int, mixed>
- Returns a file list of the directory passed in.
- move() : mixed
- Moves a file in the database and the file system.
- read() : string
- Retrieves a file from the VFS.
- readByteRange() : string
- Retrieves a part of a file from the VFS. Particularly useful when reading large files which would exceed the PHP memory limits if they were stored in a string.
- readFile() : string
- Retrieves a file from the VFS as an on-disk local file.
- readStream() : resource
- Open a read-only stream to a file in the VFS.
- rename() : mixed
- Rename a file or folder in the VFS.
- setParams() : mixed
- Sets configuration parameters.
- setQuota() : mixed
- Sets the VFS quota limit.
- setQuotaRoot() : mixed
- Sets the VFS quota root.
- size() : int
- Retrieves the size of a file from the VFS.
- write() : mixed
- Store a file in the VFS, with the data copied from a temporary file.
- writeData() : mixed
- Store a file in the VFS from raw data.
- _checkDestination() : mixed
- Checks whether a source and destination directory are the same.
- _checkQuotaDelete() : mixed
- Checks the quota when preparing to delete data.
- _checkQuotaWrite() : mixed
- Checks the quota when preparing to write data.
- _connect() : mixed
- Attempts to open a persistent connection to the SQL server.
- _copyRecursive() : mixed
- Recursively copies a directory through the backend.
- _ensureSeekable() : mixed
- _filterMatch() : bool
- Returns whether or not a file or directory name matches an filter element.
- _getDataSize() : int
- Return the size of $data.
- _getNativePath() : string
- Return a full filename on the native filesystem, from a VFS path and name.
- _getPath() : mixed
- Returns the full path of an item.
- _getSQLNativePath() : string
- Return a full SQL filename on the native filesystem, from a VFS path and name.
- _getUnixPerms() : string
- Return Unix style perms.
- _listFolder() : array<string|int, mixed>
- Returns an unsorted file list of the specified directory.
- _recursiveCopy() : mixed
- Recursively copies the contents of a folder to a destination.
- _recursiveLFSDelete() : mixed
- Delete a folders contents from the VFS, recursively.
- _recursiveSQLDelete() : mixed
- Delete a folders contents from the VFS in the SQL database, recursively.
- _recursiveSQLRename() : mixed
- Renames all child paths.
- _throwException() : mixed
- Completes an exception with a detailed error message and throws it.
- _writeSQLData() : mixed
- Store a files information within the database.
Constants
FILE
public
mixed
FILE
= 1
FOLDER
public
mixed
FOLDER
= 2
Properties
$_credentials
List of additional credentials required for this VFS backend (example: For FTP, we need a username and password to log in to the server with).
protected
array<string|int, mixed>
$_credentials
= array()
$_db
Handle for the current database connection.
protected
DB
$_db
= \false
$_features
List of features that the VFS driver supports.
protected
array<string|int, mixed>
$_features
= array('readByteRange' => \false)
$_params
Hash containing connection parameters.
protected
array<string|int, mixed>
$_params
= array()
$_permissions
List of permissions and if they can be changed in this VFS backend.
protected
array<string|int, mixed>
$_permissions
= array('owner' => array('read' => \false, 'write' => \false, 'execute' => \false), 'group' => array('read' => \false, 'write' => \false, 'execute' => \false), 'all' => array('read' => \false, 'write' => \false, 'execute' => \false))
$_vfsSize
The current size, in bytes, of the VFS tree.
protected
int
$_vfsSize
= \null
Methods
__construct()
Constructor.
public
__construct([array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $params : array<string|int, mixed> = array()
-
A hash containing connection parameters.
Return values
mixed —autocreatePath()
Automatically creates any necessary parent directories in the specified $path.
public
autocreatePath(string $path) : mixed
Parameters
- $path : string
-
The VFS path to autocreate.
Tags
Return values
mixed —changePermissions()
Changes permissions for an item on the VFS.
public
changePermissions(string $path, string $name, string $permission) : mixed
Parameters
- $path : string
-
The parent folder of the item.
- $name : string
-
The name of the item.
- $permission : string
-
The permission to set.
Tags
Return values
mixed —checkCredentials()
Checks the credentials that we have by calling _connect(), to see if there is a valid login.
public
checkCredentials() : mixed
Tags
Return values
mixed —copy()
Copies a file through the backend.
public
copy(string $path, string $name, string $dest[, bool $autocreate = false ]) : mixed
Parameters
- $path : string
-
The path to store the file in.
- $name : string
-
The filename to use.
- $dest : string
-
The destination of the file.
- $autocreate : bool = false
-
Automatically create directories?
Tags
Return values
mixed —createFolder()
Creates a folder on the VFS.
public
createFolder(string $path, string $name) : mixed
Parameters
- $path : string
-
Holds the path of directory to create folder.
- $name : string
-
Holds the name of the new folder.
Tags
Return values
mixed —delete()
Alias to deleteFile()
public
delete(mixed $path, mixed $name) : mixed
Parameters
- $path : mixed
- $name : mixed
Return values
mixed —deleteFile()
Delete a file from the VFS.
public
deleteFile(string $path, string $name) : mixed
Parameters
- $path : string
-
The path to store the file in.
- $name : string
-
The filename to use.
Tags
Return values
mixed —deleteFolder()
Delete a folder from the VFS.
public
deleteFolder(string $path, string $name[, bool $recursive = false ]) : mixed
Parameters
- $path : string
-
The path to delete the folder from.
- $name : string
-
The foldername to use.
- $recursive : bool = false
-
Force a recursive delete?
Tags
Return values
mixed —emptyFolder()
Recursively remove all files and subfolders from the given folder.
public
emptyFolder(string $path) : mixed
Parameters
- $path : string
-
The path of the folder to empty.
Tags
Return values
mixed —exists()
Returns if a given file or folder exists in a folder.
public
exists(string $path, string $name) : bool
Parameters
- $path : string
-
The path to the folder.
- $name : string
-
The file or folder name.
Return values
bool —True if it exists, false otherwise.
getCurrentDirectory()
Returns the current working directory of the VFS backend.
public
getCurrentDirectory() : string
Return values
string —The current working directory.
getFolderSize()
Returns the size of a folder.
public
getFolderSize([string $path = null ]) : int
Parameters
- $path : string = null
-
The path of the folder.
Tags
Return values
int —The size of the folder, in bytes.
getModifiablePermissions()
Returns an array specifying what permissions are changeable for this VFS implementation.
public
getModifiablePermissions() : array<string|int, mixed>
Return values
array<string|int, mixed> —Changeable permisions.
getParam()
Returns configuration parameters.
public
getParam(string $name) : mixed
Parameters
- $name : string
-
The parameter to return.
Return values
mixed —The parameter value or null if it doesn't exist.
getQuota()
Get quota information (used/allocated), in bytes.
public
getQuota() : mixed
Tags
Return values
mixed —An associative array.
'limit' = Maximum quota allowed 'usage' = Currently used portion of quota (in bytes)
getRequiredCredentials()
Returns the list of additional credentials required, if any.
public
getRequiredCredentials() : array<string|int, mixed>
Return values
array<string|int, mixed> —Credential list.
getVFSSize()
Returns the size of the VFS item.
public
getVFSSize() : int
Return values
int —The size, in bytes, of the VFS item.
hasFeature()
Returns whether the drivers supports a certain feature.
public
hasFeature(string $feature) : bool
Parameters
Return values
bool —True if the feature is supported.
isFolder()
Checks if a given item is a folder.
public
isFolder(string $path, string $name) : bool
Parameters
- $path : string
-
The parent folder.
- $name : string
-
The item name.
Return values
bool —True if it is a folder, false otherwise.
listFolder()
Returns a file list of the directory passed in.
public
listFolder(string $path[, string|array<string|int, mixed> $filter = null ][, bool $dotfiles = true ][, bool $dironly = false ][, bool $recursive = false ]) : array<string|int, mixed>
Parameters
- $path : string
-
The path of the directory.
- $filter : string|array<string|int, mixed> = null
-
Regular expression(s) to filter file/directory name on.
- $dotfiles : bool = true
-
Show dotfiles?
- $dironly : bool = false
-
Show only directories?
- $recursive : bool = false
-
Return all directory levels recursively?
Tags
Return values
array<string|int, mixed> —File list.
move()
Moves a file in the database and the file system.
public
move(string $path, string $name, string $dest[, bool $autocreate = false ]) : mixed
Parameters
- $path : string
-
The path to store the file in.
- $name : string
-
The old filename.
- $dest : string
-
The new filename.
- $autocreate : bool = false
-
Automatically create directories?
Tags
Return values
mixed —read()
Retrieves a file from the VFS.
public
read(string $path, string $name) : string
Parameters
- $path : string
-
The pathname to the file.
- $name : string
-
The filename to retrieve.
Tags
Return values
string —The file data.
readByteRange()
Retrieves a part of a file from the VFS. Particularly useful when reading large files which would exceed the PHP memory limits if they were stored in a string.
public
readByteRange(string $path, string $name, int &$offset, int $length, int &$remaining) : string
Parameters
- $path : string
-
The pathname to the file.
- $name : string
-
The filename to retrieve.
- $offset : int
-
The offset of the part. (The new offset will be stored in here).
- $length : int
-
The length of the part. If the length = -1, the whole part after the offset is retrieved. If more bytes are given as exists after the given offset. Only the available bytes are read.
- $remaining : int
-
The bytes that are left, after the part that is retrieved.
Tags
Return values
string —The file data.
readFile()
Retrieves a file from the VFS as an on-disk local file.
public
readFile(string $path, string $name) : string
This function provides a file on local disk with the data of a VFS file in it. This file cannot be modified! The behavior if you do modify it is undefined. It will be removed at the end of the request.
Parameters
- $path : string
-
The pathname to the file.
- $name : string
-
The filename to retrieve.
Tags
Return values
string —A local filename.
readStream()
Open a read-only stream to a file in the VFS.
public
readStream(string $path, string $name) : resource
Parameters
- $path : string
-
The pathname to the file.
- $name : string
-
The filename to retrieve.
Tags
Return values
resource —The stream.
rename()
Rename a file or folder in the VFS.
public
rename(string $oldpath, string $oldname, string $newpath, string $newname) : mixed
Parameters
- $oldpath : string
-
The old path to the file.
- $oldname : string
-
The old filename.
- $newpath : string
-
The new path of the file.
- $newname : string
-
The new filename.
Tags
Return values
mixed —setParams()
Sets configuration parameters.
public
setParams([array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $params : array<string|int, mixed> = array()
-
An associative array with parameter names as keys.
Return values
mixed —setQuota()
Sets the VFS quota limit.
public
setQuota(int $quota[, int $metric = Horde_Vfs::QUOTA_METRIC_BYTE ]) : mixed
Parameters
- $quota : int
-
The limit to apply.
- $metric : int = Horde_Vfs::QUOTA_METRIC_BYTE
-
The metric to multiply the quota into.
Return values
mixed —setQuotaRoot()
Sets the VFS quota root.
public
setQuotaRoot(string $dir) : mixed
Parameters
- $dir : string
-
The root directory for the quota determination.
Return values
mixed —size()
Retrieves the size of a file from the VFS.
public
size(string $path, string $name) : int
Parameters
- $path : string
-
The pathname to the file.
- $name : string
-
The filename to retrieve.
Tags
Return values
int —The file size.
write()
Store a file in the VFS, with the data copied from a temporary file.
public
write(string $path, string $name, string $tmpFile[, bool $autocreate = false ]) : mixed
Parameters
- $path : string
-
The path to store the file in.
- $name : string
-
The filename to use.
- $tmpFile : string
-
The temporary file containing the data to be stored.
- $autocreate : bool = false
-
Automatically create directories?
Tags
Return values
mixed —writeData()
Store a file in the VFS from raw data.
public
writeData(string $path, string $name, string $data[, bool $autocreate = false ]) : mixed
Parameters
- $path : string
-
The path to store the file in.
- $name : string
-
The filename to use.
- $data : string
-
The file data.
- $autocreate : bool = false
-
Automatically create directories?
Tags
Return values
mixed —_checkDestination()
Checks whether a source and destination directory are the same.
protected
_checkDestination(string $path, string $dest) : mixed
Parameters
- $path : string
-
A source path.
- $dest : string
-
A destination path.
Tags
Return values
mixed —_checkQuotaDelete()
Checks the quota when preparing to delete data.
protected
_checkQuotaDelete(string $path, string $name) : mixed
Parameters
- $path : string
-
The path the file is located in.
- $name : string
-
The filename.
Tags
Return values
mixed —_checkQuotaWrite()
Checks the quota when preparing to write data.
protected
_checkQuotaWrite(string $mode, string $data[, string $path = null ][, string $name = null ]) : mixed
Parameters
- $mode : string
-
Either 'string' or 'file'. If 'string', $data is the data to be written. If 'file', $data is the filename containing the data to be written.
- $data : string
-
Either the data or the filename to the data.
- $path : string = null
-
The path the file is located in.
- $name : string = null
-
The filename.
Tags
Return values
mixed —_connect()
Attempts to open a persistent connection to the SQL server.
protected
_connect() : mixed
Tags
Return values
mixed —_copyRecursive()
Recursively copies a directory through the backend.
protected
_copyRecursive(string $path, string $name, string $dest) : mixed
Parameters
- $path : string
-
The path of the original file.
- $name : string
-
The name of the original file.
- $dest : string
-
The name of the destination directory.
Tags
Return values
mixed —_ensureSeekable()
protected
_ensureSeekable(mixed $stream) : mixed
Parameters
- $stream : mixed
Return values
mixed —_filterMatch()
Returns whether or not a file or directory name matches an filter element.
protected
_filterMatch(string|array<string|int, mixed> $filter, string $filename) : bool
Parameters
- $filter : string|array<string|int, mixed>
-
Regular expression(s) to build the filter from.
- $filename : string
-
String containing the file/directory name to match.
Return values
bool —True on match, false on no match.
_getDataSize()
Return the size of $data.
protected
_getDataSize(string|resource $data) : int
Parameters
- $data : string|resource
-
The data.
Return values
int —The data length.
_getNativePath()
Return a full filename on the native filesystem, from a VFS path and name.
protected
_getNativePath(string $path, string $name) : string
Parameters
- $path : string
-
The VFS file path.
- $name : string
-
The VFS filename.
Return values
string —The full native filename.
_getPath()
Returns the full path of an item.
protected
_getPath(string $path, string $name) : mixed
Parameters
- $path : string
-
The path of directory of the item.
- $name : string
-
The name of the item.
Return values
mixed —Full path when $path isset and just $name when not set.
_getSQLNativePath()
Return a full SQL filename on the native filesystem, from a VFS path and name.
protected
_getSQLNativePath(string $path, string $name) : string
Parameters
- $path : string
-
The VFS file path.
- $name : string
-
The VFS filename.
Return values
string —The full native filename.
_getUnixPerms()
Return Unix style perms.
protected
_getUnixPerms(int $perms) : string
Parameters
- $perms : int
-
The permissions to set.
Return values
string —Unix style perms.
_listFolder()
Returns an unsorted file list of the specified directory.
protected
_listFolder(string $path[, string|array<string|int, mixed> $filter = null ][, bool $dotfiles = true ][, bool $dironly = false ]) : array<string|int, mixed>
Parameters
- $path : string
-
The path of the directory.
- $filter : string|array<string|int, mixed> = null
-
Regular expression(s) to filter file/directory name on.
- $dotfiles : bool = true
-
Show dotfiles?
- $dironly : bool = false
-
Show only directories?
Tags
Return values
array<string|int, mixed> —File list.
_recursiveCopy()
Recursively copies the contents of a folder to a destination.
protected
_recursiveCopy(string $path, string $name, string $dest) : mixed
Parameters
- $path : string
-
The path to store the directory in.
- $name : string
-
The name of the directory.
- $dest : string
-
The destination of the directory.
Tags
Return values
mixed —_recursiveLFSDelete()
Delete a folders contents from the VFS, recursively.
protected
_recursiveLFSDelete(string $path, string $name) : mixed
Parameters
- $path : string
-
The path of the folder.
- $name : string
-
The foldername to use.
Tags
Return values
mixed —_recursiveSQLDelete()
Delete a folders contents from the VFS in the SQL database, recursively.
protected
_recursiveSQLDelete(string $path, string $name) : mixed
Parameters
- $path : string
-
The path of the folder.
- $name : string
-
The foldername to use.
Tags
Return values
mixed —_recursiveSQLRename()
Renames all child paths.
protected
_recursiveSQLRename(string $oldpath, string $oldname, string $newpath, string $newname) : mixed
Parameters
- $oldpath : string
-
The old path of the folder to rename.
- $oldname : string
-
The old name.
- $newpath : string
-
The new path of the folder to rename.
- $newname : string
-
The new name.
Tags
Return values
mixed —_throwException()
Completes an exception with a detailed error message and throws it.
protected
_throwException(Exception $e) : mixed
Parameters
- $e : Exception
-
The prepared exception.
Tags
Return values
mixed —_writeSQLData()
Store a files information within the database.
protected
_writeSQLData(string $path, string $name) : mixed
Parameters
- $path : string
-
The path to store the file in.
- $name : string
-
The filename to use.