\Horde_Vfs_SqlFile

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.

Summary

Methods
Properties
Constants
__construct()
size()
read()
readFile()
readStream()
readByteRange()
write()
move()
copy()
writeData()
deleteFile()
deleteFolder()
createFolder()
isFolder()
changePermissions()
rename()
exists()
hasFeature()
checkCredentials()
setParams()
getParam()
getFolderSize()
delete()
autocreatePath()
emptyFolder()
listFolder()
getCurrentDirectory()
getRequiredCredentials()
getModifiablePermissions()
getVFSSize()
setQuota()
setQuotaRoot()
getQuota()
No public properties found
FILE
FOLDER
_listFolder()
_getUnixPerms()
_getNativePath()
_connect()
_throwException()
_checkDestination()
_copyRecursive()
_filterMatch()
_checkQuotaWrite()
_getDataSize()
_ensureSeekable()
_checkQuotaDelete()
_getPath()
_recursiveCopy()
_writeSQLData()
_recursiveSQLRename()
_recursiveSQLDelete()
_recursiveLFSDelete()
_getSQLNativePath()
$_permissions
$_features
$_params
$_credentials
$_vfsSize
$_db
N/A
No private methods found
No private properties found
N/A

Constants

FILE

FILE

FOLDER

FOLDER

Properties

$_permissions

$_permissions : array

List of permissions and if they can be changed in this VFS backend.

Type

array

$_features

$_features : array

List of features that the VFS driver supports.

Type

array

$_params

$_params : array

Hash containing connection parameters.

Type

array

$_credentials

$_credentials : array

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).

Type

array

$_vfsSize

$_vfsSize : integer

The current size, in bytes, of the VFS tree.

Type

integer

$_db

$_db : \DB

Handle for the current database connection.

Type

\DB

Methods

__construct()

__construct(array  $params = array()) 

Constructor.

Parameters

array $params

A hash containing connection parameters.

size()

size(string  $path, string  $name) : integer

Retrieves the size of a file from the VFS.

Parameters

string $path

The pathname to the file.

string $name

The filename to retrieve.

Throws

\Horde_Vfs_Exception

Returns

integer —

The file size.

read()

read(string  $path, string  $name) : string

Retrieves a file from the VFS.

Parameters

string $path

The pathname to the file.

string $name

The filename to retrieve.

Throws

\Horde_Vfs_Exception

Returns

string —

The file data.

readFile()

readFile(string  $path, string  $name) : string

Retrieves a file from the VFS as an on-disk local file.

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

string $path

The pathname to the file.

string $name

The filename to retrieve.

Throws

\Horde_Vfs_Exception

Returns

string —

A local filename.

readStream()

readStream(string  $path, string  $name) : resource

Open a read-only stream to a file in the VFS.

Parameters

string $path

The pathname to the file.

string $name

The filename to retrieve.

Throws

\Horde_Vfs_Exception

Returns

resource —

The stream.

readByteRange()

readByteRange(string  $path, string  $name, integer  $offset, integer  $length, integer  $remaining) : 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.

Parameters

string $path

The pathname to the file.

string $name

The filename to retrieve.

integer $offset

The offset of the part. (The new offset will be stored in here).

integer $length

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.

integer $remaining

The bytes that are left, after the part that is retrieved.

Throws

\Horde_Vfs_Exception

Returns

string —

The file data.

write()

write(string  $path, string  $name, string  $tmpFile, boolean  $autocreate = false) 

Store a file in the VFS, with the data copied from a temporary file.

Parameters

string $path

The path to store the file in.

string $name

The filename to use.

string $tmpFile

The temporary file containing the data to be stored.

boolean $autocreate

Automatically create directories?

Throws

\Horde_Vfs_Exception

move()

move(string  $path, string  $name, string  $dest, boolean  $autocreate = false) 

Moves a file in the database and the file system.

Parameters

string $path

The path to store the file in.

string $name

The old filename.

string $dest

The new filename.

boolean $autocreate

Automatically create directories?

Throws

\Horde_Vfs_Exception

copy()

copy(string  $path, string  $name, string  $dest, boolean  $autocreate = false) 

Copies a file through the backend.

Parameters

string $path

The path to store the file in.

string $name

The filename to use.

string $dest

The destination of the file.

boolean $autocreate

Automatically create directories?

Throws

\Horde_Vfs_Exception

writeData()

writeData(string  $path, string  $name, string  $data, boolean  $autocreate = false) 

Store a file in the VFS from raw data.

Parameters

string $path

The path to store the file in.

string $name

The filename to use.

string $data

The file data.

boolean $autocreate

Automatically create directories?

Throws

\Horde_Vfs_Exception

deleteFile()

deleteFile(string  $path, string  $name) 

Delete a file from the VFS.

Parameters

string $path

The path to store the file in.

string $name

The filename to use.

Throws

\Horde_Vfs_Exception

deleteFolder()

deleteFolder(string  $path, string  $name, boolean  $recursive = false) 

Delete a folder from the VFS.

Parameters

string $path

The path to delete the folder from.

string $name

The foldername to use.

boolean $recursive

Force a recursive delete?

Throws

\Horde_Vfs_Exception

createFolder()

createFolder(string  $path, string  $name) 

Creates a folder on the VFS.

Parameters

string $path

Holds the path of directory to create folder.

string $name

Holds the name of the new folder.

Throws

\Horde_Vfs_Exception

isFolder()

isFolder(string  $path, string  $name) : boolean

Checks if a given item is a folder.

Parameters

string $path

The parent folder.

string $name

The item name.

Returns

boolean —

True if it is a folder, false otherwise.

changePermissions()

changePermissions(string  $path, string  $name, string  $permission) 

Changes permissions for an item on the VFS.

Parameters

string $path

The parent folder of the item.

string $name

The name of the item.

string $permission

The permission to set.

Throws

\Horde_Vfs_Exception

rename()

rename(string  $oldpath, string  $oldname, string  $newpath, string  $newname) 

Rename a file or folder in the VFS.

Parameters

string $oldpath

The old path to the file.

string $oldname

The old filename.

string $newpath

The new path of the file.

string $newname

The new filename.

Throws

\Horde_Vfs_Exception

exists()

exists(string  $path, string  $name) : boolean

Returns if a given file or folder exists in a folder.

Parameters

string $path

The path to the folder.

string $name

The file or folder name.

Returns

boolean —

True if it exists, false otherwise.

hasFeature()

hasFeature(string  $feature) : boolean

Returns whether the drivers supports a certain feature.

Parameters

string $feature

A feature name. See {@link $_features} for a list of possible features.

Returns

boolean —

True if the feature is supported.

checkCredentials()

checkCredentials() 

Checks the credentials that we have by calling _connect(), to see if there is a valid login.

Throws

\Horde_Vfs_Exception

setParams()

setParams(array  $params = array()) 

Sets configuration parameters.

Parameters

array $params

An associative array with parameter names as keys.

getParam()

getParam(string  $name) : mixed

Returns configuration parameters.

Parameters

string $name

The parameter to return.

Returns

mixed —

The parameter value or null if it doesn't exist.

getFolderSize()

getFolderSize(string  $path = null) : integer

Returns the size of a folder.

Parameters

string $path

The path of the folder.

Throws

\Horde_Vfs_Exception

Returns

integer —

The size of the folder, in bytes.

delete()

delete(  $path,   $name) 

Alias to deleteFile()

Parameters

$path
$name

autocreatePath()

autocreatePath(string  $path) 

Automatically creates any necessary parent directories in the specified $path.

Parameters

string $path

The VFS path to autocreate.

Throws

\Horde_Vfs_Exception

emptyFolder()

emptyFolder(string  $path) 

Recursively remove all files and subfolders from the given folder.

Parameters

string $path

The path of the folder to empty.

Throws

\Horde_Vfs_Exception

listFolder()

listFolder(string  $path, string|array  $filter = null, boolean  $dotfiles = true, boolean  $dironly = false, boolean  $recursive = false) : array

Returns a file list of the directory passed in.

Parameters

string $path

The path of the directory.

string|array $filter

Regular expression(s) to filter file/directory name on.

boolean $dotfiles

Show dotfiles?

boolean $dironly

Show only directories?

boolean $recursive

Return all directory levels recursively?

Throws

\Horde_Vfs_Exception

Returns

array —

File list.

getCurrentDirectory()

getCurrentDirectory() : string

Returns the current working directory of the VFS backend.

Returns

string —

The current working directory.

getRequiredCredentials()

getRequiredCredentials() : array

Returns the list of additional credentials required, if any.

Returns

array —

Credential list.

getModifiablePermissions()

getModifiablePermissions() : array

Returns an array specifying what permissions are changeable for this VFS implementation.

Returns

array —

Changeable permisions.

getVFSSize()

getVFSSize() : integer

Returns the size of the VFS item.

Returns

integer —

The size, in bytes, of the VFS item.

setQuota()

setQuota(integer  $quota, integer  $metric = \Horde_Vfs::QUOTA_METRIC_BYTE) 

Sets the VFS quota limit.

Parameters

integer $quota

The limit to apply.

integer $metric

The metric to multiply the quota into.

setQuotaRoot()

setQuotaRoot(string  $dir) 

Sets the VFS quota root.

Parameters

string $dir

The root directory for the quota determination.

getQuota()

getQuota() : mixed

Get quota information (used/allocated), in bytes.

Throws

\Horde_Vfs_Exception

Returns

mixed —

An associative array.

'limit' = Maximum quota allowed
'usage' = Currently used portion of quota (in bytes)

_listFolder()

_listFolder(string  $path, string|array  $filter = null, boolean  $dotfiles = true, boolean  $dironly = false) : array

Returns an unsorted file list of the specified directory.

Parameters

string $path

The path of the directory.

string|array $filter

Regular expression(s) to filter file/directory name on.

boolean $dotfiles

Show dotfiles?

boolean $dironly

Show only directories?

Throws

\Horde_Vfs_Exception

Returns

array —

File list.

_getUnixPerms()

_getUnixPerms(integer  $perms) : string

Return Unix style perms.

Parameters

integer $perms

The permissions to set.

Returns

string —

Unix style perms.

_getNativePath()

_getNativePath(string  $path, string  $name) : string

Return a full filename on the native filesystem, from a VFS path and name.

Parameters

string $path

The VFS file path.

string $name

The VFS filename.

Returns

string —

The full native filename.

_connect()

_connect() 

Attempts to open a persistent connection to the SQL server.

Throws

\Horde_Vfs_Exception

_throwException()

_throwException(\Exception  $e) 

Completes an exception with a detailed error message and throws it.

Parameters

\Exception $e

The prepared exception.

Throws

\Exception

The exception $e with error details attached.

_checkDestination()

_checkDestination(string  $path, string  $dest) 

Checks whether a source and destination directory are the same.

Parameters

string $path

A source path.

string $dest

A destination path.

Throws

\Horce_Vfs_Exception

of both paths are the same.

_copyRecursive()

_copyRecursive(string  $path, string  $name, string  $dest) 

Recursively copies a directory through the backend.

Parameters

string $path

The path of the original file.

string $name

The name of the original file.

string $dest

The name of the destination directory.

Throws

\Horde_Vfs_Exception

_filterMatch()

_filterMatch(string|array  $filter, string  $filename) : boolean

Returns whether or not a file or directory name matches an filter element.

Parameters

string|array $filter

Regular expression(s) to build the filter from.

string $filename

String containing the file/directory name to match.

Returns

boolean —

True on match, false on no match.

_checkQuotaWrite()

_checkQuotaWrite(string  $mode, string  $data, string  $path = null, string  $name = null) 

Checks the quota when preparing to write data.

Parameters

string $mode

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.

string $data

Either the data or the filename to the data.

string $path

The path the file is located in.

string $name

The filename.

Throws

\Horde_Vfs_Exception

_getDataSize()

_getDataSize(string|resource  $data) : integer

Return the size of $data.

Parameters

string|resource $data

The data.

Returns

integer —

The data length.

_ensureSeekable()

_ensureSeekable(  $stream) 

Parameters

$stream

_checkQuotaDelete()

_checkQuotaDelete(string  $path, string  $name) 

Checks the quota when preparing to delete data.

Parameters

string $path

The path the file is located in.

string $name

The filename.

Throws

\Horde_Vfs_Exception

_getPath()

_getPath(string  $path, string  $name) : mixed

Returns the full path of an item.

Parameters

string $path

The path of directory of the item.

string $name

The name of the item.

Returns

mixed —

Full path when $path isset and just $name when not set.

_recursiveCopy()

_recursiveCopy(string  $path, string  $name, string  $dest) 

Recursively copies the contents of a folder to a destination.

Parameters

string $path

The path to store the directory in.

string $name

The name of the directory.

string $dest

The destination of the directory.

Throws

\Horde_Vfs_Exception

_writeSQLData()

_writeSQLData(string  $path, string  $name) 

Store a files information within the database.

Parameters

string $path

The path to store the file in.

string $name

The filename to use.

Throws

\Horde_Vfs_Exception

_recursiveSQLRename()

_recursiveSQLRename(string  $oldpath, string  $oldname, string  $newpath, string  $newname) 

Renames all child paths.

Parameters

string $oldpath

The old path of the folder to rename.

string $oldname

The old name.

string $newpath

The new path of the folder to rename.

string $newname

The new name.

Throws

\Horde_Vfs_Exception

_recursiveSQLDelete()

_recursiveSQLDelete(string  $path, string  $name) 

Delete a folders contents from the VFS in the SQL database, recursively.

Parameters

string $path

The path of the folder.

string $name

The foldername to use.

Throws

\Horde_Vfs_Exception

_recursiveLFSDelete()

_recursiveLFSDelete(string  $path, string  $name) 

Delete a folders contents from the VFS, recursively.

Parameters

string $path

The path of the folder.

string $name

The foldername to use.

Throws

\Horde_Vfs_Exception

_getSQLNativePath()

_getSQLNativePath(string  $path, string  $name) : string

Return a full SQL filename on the native filesystem, from a VFS path and name.

Parameters

string $path

The VFS file path.

string $name

The VFS filename.

Returns

string —

The full native filename.