FileSystem
final class FileSystem
File system tool.
Methods
Creates a directory if it does not exist, including parent directories.
Copies a file or an entire directory. Overwrites existing files and directories by default.
Opens file and returns resource.
Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first.
Renames or moves a file or a directory. Overwrites existing files and directories by default.
Reads the content of a file.
Reads the file content line by line. Because it reads continuously as we iterate over the lines, it is possible to read files larger than the available memory.
Writes the string to a file.
Sets file permissions to $fileMode
or directory permissions to $dirMode
.
Determines if the path is absolute.
Normalizes ..
and .
and directory separators in path.
Joins all segments of the path and normalizes the result.
Resolves a path against a base path. If the path is absolute, returns it directly, if it's relative, joins it with the base path.
Converts backslashes to slashes.
Converts slashes to platform-specific directory separators.
Details
at line 26
static void
createDir(string $dir, int $mode = 0777)
Creates a directory if it does not exist, including parent directories.
at line 44
static void
copy(string $origin, string $target, bool $overwrite = true)
Copies a file or an entire directory. Overwrites existing files and directories by default.
at line 84
static resource
open(string $path, string $mode)
Opens file and returns resource.
at line 102
static void
delete(string $path)
Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first.
at line 134
static void
rename(string $origin, string $target, bool $overwrite = true)
Renames or moves a file or a directory. Overwrites existing files and directories by default.
at line 164
static string
read(string $file)
Reads the content of a file.
at line 185
static Generator
readLines(string $file, bool $stripNewLines = true)
Reads the file content line by line. Because it reads continuously as we iterate over the lines, it is possible to read files larger than the available memory.
at line 214
static void
write(string $file, string $content, int|null $mode = 0666)
Writes the string to a file.
at line 241
static void
makeWritable(string $path, int $dirMode = 0777, int $fileMode = 0666)
Sets file permissions to $fileMode
or directory permissions to $dirMode
.
Recursively traverses and sets permissions on the entire contents of the directory as well.
at line 274
static bool
isAbsolute(string $path)
Determines if the path is absolute.
at line 283
static string
normalizePath(string $path)
Normalizes ..
and .
and directory separators in path.
at line 304
static string
joinPaths(string ...$paths)
Joins all segments of the path and normalizes the result.
at line 313
static string
resolvePath(string $basePath, string $path)
Resolves a path against a base path. If the path is absolute, returns it directly, if it's relative, joins it with the base path.
at line 326
static string
unixSlashes(string $path)
Converts backslashes to slashes.
at line 335
static string
platformSlashes(string $path)
Converts slashes to platform-specific directory separators.