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. Creates the parent directory if it does not exist. Pass null as $mode to skip chmod.
Sets file permissions to $fileMode or directory permissions to $dirMode.
Determines if the path is absolute.
Determines whether the string is a valid cross-platform filename without any path information.
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 24
static void
createDir(string $dir, int $mode = 0777)
Creates a directory if it does not exist, including parent directories.
at line 42
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 83
static resource
open(string $path, string $mode)
Opens file and returns resource.
at line 101
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. Creates the parent directory if it does not exist. Pass null as $mode to skip chmod.
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 275
static bool
isAbsolute(string $path)
Determines if the path is absolute.
at line 284
static bool
isValidFilename(string $name)
Determines whether the string is a valid cross-platform filename without any path information.
at line 297
static string
normalizePath(string $path)
Normalizes .. and . and directory separators in path.
at line 318
static string
joinPaths(string ...$paths)
Joins all segments of the path and normalizes the result.
at line 327
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 340
static string
unixSlashes(string $path)
Converts backslashes to slashes.
at line 349
static string
platformSlashes(string $path)
Converts slashes to platform-specific directory separators.