Filesystem
class Filesystem
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.
Determine if the given path reads from a phar archive other than the running one.
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.
Get all the directories within a given directory (recursive).
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.
Clear file status cache.
Flush all static state.
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 36
bool
exists(string $path)
Determine if a file or directory exists.
at line 48
bool
missing(string $path)
Determine if a file or directory is missing.
at line 58
string
get(string $path, bool $lock = false)
Get the contents of a file.
at line 78
mixed
json(string $path, int $flags = 0, bool $lock = false)
Get the contents of a file as decoded JSON.
at line 86
string
sharedGet(string $path)
Get contents of a file with shared access.
at line 144
mixed
getRequire(string $path, array $data = [])
Get the returned value of a file.
at line 165
mixed
requireOnce(string $path, array $data = [])
Require the given file once.
at line 186
LazyCollection
lines(string $path)
Get the contents of a file one line at a time.
at line 211
string|false
hash(string $path, string $algorithm = 'xxh128')
Get the hash of the file at the given path.
Defaults to xxh128 for fast app-internal file hashing. Pass a specific algorithm explicitly when an external protocol requires one.
at line 221
int|false
put(string $path, resource|string $contents, bool $lock = false)
Write the contents of a file.
at line 229
void
replace(string $path, string $content, int|null $mode = null)
Write the contents of a file, replacing it atomically if it already exists.
at line 264
void
replaceInFile(array|string $search, array|string $replace, string $path)
Replace a given string within a given file.
at line 282
int|false
prepend(string $path, string $data)
Prepend to a file.
at line 294
int|false
append(string $path, string $data, bool $lock = false)
Append to a file.
at line 302
string|bool
chmod(string $path, int|null $mode = null)
Get or set UNIX mode of a file or directory.
at line 318
bool
delete(array|string $paths)
Delete the file at a given path.
at line 342
bool
move(string $path, string $target)
Move a file to a new location.
at line 350
bool
copy(string $path, string $target)
Copy a file to a new location.
at line 358
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.
at line 381
void
relativeLink(string $target, string $link)
Create a relative symlink to the target file or directory.
at line 399
string
name(string $path)
Extract the file name from a file path.
at line 407
string
basename(string $path)
Extract the trailing name component from a file path.
at line 415
string
dirname(string $path)
Extract the parent directory from a file path.
at line 423
string
extension(string $path)
Extract the file extension from a file path.
at line 433
string|null
guessExtension(string $path)
Guess the file extension from the MIME type of a given file.
at line 449
string|false
type(string $path)
Get the file type of a given file.
at line 457
string|false
mimeType(string $path)
Get the MIME type of a given file.
at line 467
int|false
size(string $path)
Get the file size of a given file.
at line 475
int|false
lastModified(string $path)
Get the file's last modification time.
at line 485
bool
isDirectory(string $directory)
Determine if the given path is a directory.
at line 493
bool
isEmptyDirectory(string $directory, bool $ignoreDotFiles = false)
Determine if the given path is a directory that does not contain any other files or directories.
at line 501
bool
isReadable(string $path)
Determine if the given path is readable.
at line 509
bool
isWritable(string $path)
Determine if the given path is writable.
at line 517
bool
hasSameHash(string $firstFile, string $secondFile)
Determine if two files are the same by comparing their hashes.
at line 527
bool
isFile(string $file)
Determine if the given path is a file.
at line 541
protected bool
hasDangerousStreamWrapper(string $path)
Determine if the given path reads from a phar archive other than the running one.
The require helpers use isFile(), so this also prevents them from executing scripts from uploaded archives.
at line 556
array|false
glob(string $pattern, int $flags = 0)
Find path names matching a given pattern.
at line 566
array
files(array|string $directory, bool $hidden = false, array|string|int $depth = 0)
Get an array of all files in a directory.
at line 579
array
allFiles(array|string $directory, bool $hidden = false)
Get all of the files from the given directory (recursive).
at line 587
array
directories(array|string $directory, array|string|int $depth = 0)
Get all of the directories within a given directory.
at line 601
array
allDirectories(array|string $directory)
Get all the directories within a given directory (recursive).
at line 609
void
ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true)
Ensure a directory exists.
at line 623
bool
makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false)
Create a directory.
at line 635
bool
moveDirectory(string $from, string $to, bool $overwrite = false)
Move a directory.
at line 647
bool
copyDirectory(string $directory, string $destination, int|null $options = null)
Copy a directory from one location to another.
at line 692
bool
deleteDirectory(string $directory, bool $preserve = false)
Recursively delete a directory.
The directory itself may be optionally preserved.
at line 750
bool
deleteDirectories(string $directory)
Remove all of the directories within a given directory.
at line 772
bool
cleanDirectory(string $directory)
Empty the specified directory of all files and folders.
at line 780
void
clearStatCache(string $path)
Clear file status cache.
at line 788
static void
flushState()
Flush all static state.