Filesystem
API reference › Scaffold › Filesystem
Runs native filesystem calls and turns the PHP warning of a failed call into a RuntimeException.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
copy() static | Copies a file, overwriting the destination. | Filesystem |
copyPermissions() static | Copies the permission bits of a file, masked by the current umask, onto another file. | Filesystem |
hash() static | Returns the hexadecimal SHA-256 hash of a file. | Filesystem |
isEmptyDirectory() static | Returns whether a directory holds no entry. | Filesystem |
mkdir() static | Creates a directory and its missing parents. | Filesystem |
read() static | Returns the content of a file. | Filesystem |
readLink() static | Returns the target of a symbolic link. | Filesystem |
remove() static | Deletes a file. | Filesystem |
removeDirectory() static | Removes an empty directory. | Filesystem |
write() static | Writes content to a file, creating or truncating it. | Filesystem |
writeAtomic() static | Writes content to a temporary file next to $path and renames it over $path, removing the temporary file when the rename fails. | Filesystem |
Method details
Section titled “Method details”copy()
Section titled “copy() ”public static function copy(string $source, string $destination, string $failure): voidCopies a file, overwriting the destination.
Parameters
| Parameter | Type | Description |
|---|---|---|
$source | string | Absolute path to the source file. |
$destination | string | Absolute path to the destination file. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Throws
RuntimeException: when the file cannot be copied.
copyPermissions()
Section titled “copyPermissions() ”public static function copyPermissions(string $source, string $destination, string $failure): voidCopies the permission bits of a file, masked by the current umask, onto another file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$source | string | Absolute path to the file whose permissions are copied. |
$destination | string | Absolute path to the file that receives the permissions. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Throws
RuntimeException: when the permissions cannot be read or set.
hash()
Section titled “hash() ”public static function hash(string $path, string $failure): stringReturns the hexadecimal SHA-256 hash of a file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the file. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Returns
string: Hexadecimal SHA-256 hash of the file content.
Throws
RuntimeException: when the file cannot be read.
isEmptyDirectory()
Section titled “isEmptyDirectory() ”public static function isEmptyDirectory(string $directory, string $failure): boolReturns whether a directory holds no entry.
Parameters
| Parameter | Type | Description |
|---|---|---|
$directory | string | Absolute path to the directory. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Returns
bool: true when the directory has no entry besides . and .., false otherwise.
Throws
RuntimeException: when the directory cannot be read.
mkdir()
Section titled “mkdir() ”public static function mkdir(string $directory, string $failure): voidCreates a directory and its missing parents.
Parameters
| Parameter | Type | Description |
|---|---|---|
$directory | string | Absolute path to the directory. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Throws
RuntimeException: when the directory cannot be created.
read()
Section titled “read() ”public static function read(string $path, string $failure): stringReturns the content of a file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the file. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Returns
string: Content of the file.
Throws
RuntimeException: when the file cannot be read.
readLink()
Section titled “readLink() ”public static function readLink(string $path, string $failure): stringReturns the target of a symbolic link.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the symbolic link. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Returns
string: Target of the link, as stored in the link.
Throws
RuntimeException: when the link cannot be read.
remove()
Section titled “remove() ”public static function remove(string $path, string $failure): voidDeletes a file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the file. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Throws
RuntimeException: when the file cannot be deleted.
removeDirectory()
Section titled “removeDirectory() ”public static function removeDirectory(string $directory, string $failure): voidRemoves an empty directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
$directory | string | Absolute path to the directory. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Throws
RuntimeException: when the directory cannot be removed.
write()
Section titled “write() ”public static function write(string $path, string $content, string $failure): voidWrites content to a file, creating or truncating it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the file. |
$content | string | Content to write. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Throws
RuntimeException: when the file cannot be written.
writeAtomic()
Section titled “writeAtomic() ”public static function writeAtomic(string $path, string $content, string $failure): voidWrites content to a temporary file next to $path and renames it over $path, removing the temporary file
when the rename fails.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the file. |
$content | string | Content to write. |
$failure | string | Message of the exception thrown on failure, before the PHP warning. |
Throws
RuntimeException: when the temporary file cannot be written, renamed or removed.