Filesystem
class Filesystem (View source)
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Determine if a file or directory exists.
Determine if a file or directory is missing.
Get the contents of a file.
Get the contents of a file as decoded JSON.
Get contents of a file with shared access.
Get the returned value of a file.
Require the given file once.
Get the contents of a file one line at a time.
Get the hash of the file at the given path.
Write the contents of a file.
Write the contents of a file, replacing it atomically if it already exists.
Replace a given string within a given file.
Prepend to a file.
Append to a file.
Get or set UNIX mode of a file or directory.
Delete the file at a given path.
Move a file to a new location.
Copy a file to a new location.
Create a symlink to the target file or directory. On Windows, a hard link is created if the target is a file.
Create a relative symlink to the target file or directory.
Extract the file name from a file path.
Extract the trailing name component from a file path.
Extract the parent directory from a file path.
Extract the file extension from a file path.
Guess the file extension from the mime-type of a given file.
Get the file type of a given file.
Get the mime-type of a given file.
Get the file size of a given file.
Get the file's last modification time.
Determine if the given path is a directory.
Determine if the given path is a directory that does not contain any other files or directories.
Determine if the given path is readable.
Determine if the given path is writable.
Determine if two files are the same by comparing their hashes.
Determine if the given path is a file.
Find path names matching a given pattern.
Get an array of all files in a directory.
Get all of the files from the given directory (recursive).
Get all of the directories within a given directory.
Ensure a directory exists.
Create a directory.
Move a directory.
Copy a directory from one location to another.
Recursively delete a directory.
Remove all of the directories within a given directory.
Empty the specified directory of all files and folders.
Details
$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
array
json(string $path, int $flags = 0, bool $lock = false)
Get the contents of a file as decoded JSON.
string|false
hash(string $path, string $algorithm = 'md5')
Get the hash of the file at the given path.
void
replace(string $path, string $content, int|null $mode = null)
Write the contents of a file, replacing it atomically if it already exists.
void
replaceInFile(array|string $search, array|string $replace, string $path)
Replace a given string within a given file.
bool|null
link(string $target, string $link)
Create a symlink to the target file or directory. On Windows, a hard link is created if the target is a file.
void
relativeLink(string $target, string $link)
Create a relative symlink to the target file or directory.
string|null
guessExtension(string $path)
Guess the file extension from the mime-type of a given file.
bool
isEmptyDirectory(string $directory, bool $ignoreDotFiles = false)
Determine if the given path is a directory that does not contain any other files or directories.
bool
hasSameHash(string $firstFile, string $secondFile)
Determine if two files are the same by comparing their hashes.
SplFileInfo[]
files(string $directory, bool $hidden = false)
Get an array of all files in a directory.
SplFileInfo[]
allFiles(string $directory, bool $hidden = false)
Get all of the files from the given directory (recursive).
void
ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true)
Ensure a directory exists.
bool
makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false)
Create a directory.
bool
copyDirectory(string $directory, string $destination, int|null $options = null)
Copy a directory from one location to another.
bool
deleteDirectory(string $directory, bool $preserve = false)
Recursively delete a directory.
The directory itself may be optionally preserved.