Documentation

FileSystem
in package

FinalYes

File system tool.

Table of Contents

Methods

copy()  : void
Copies a file or an entire directory. Overwrites existing files and directories by default.
createDir()  : void
Creates a directory if it does not exist, including parent directories.
delete()  : void
Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first.
isAbsolute()  : bool
Determines if the path is absolute.
joinPaths()  : string
Joins all segments of the path and normalizes the result.
makeWritable()  : void
Sets file permissions to `$fileMode` or directory permissions to `$dirMode`.
normalizePath()  : string
Normalizes `..` and `.` and directory separators in path.
open()  : resource
Opens file and returns resource.
platformSlashes()  : string
Converts slashes to platform-specific directory separators.
read()  : string
Reads the content of a file.
readLines()  : Generator<int, string>
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.
rename()  : void
Renames or moves a file or a directory. Overwrites existing files and directories by default.
resolvePath()  : string
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.
unixSlashes()  : string
Converts backslashes to slashes.
write()  : void
Writes the string to a file.

Methods

copy()

Copies a file or an entire directory. Overwrites existing files and directories by default.

public static copy(string $origin, string $target[, bool $overwrite = true ]) : void
Parameters
$origin : string
$target : string
$overwrite : bool = true
Tags
throws
IOException

on error occurred

throws
InvalidStateException

if $overwrite is set to false and destination already exists

createDir()

Creates a directory if it does not exist, including parent directories.

public static createDir(string $dir[, int $mode = 0777 ]) : void
Parameters
$dir : string
$mode : int = 0777
Tags
throws
IOException

on error occurred

delete()

Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first.

public static delete(string $path) : void
Parameters
$path : string
Tags
throws
IOException

on error occurred

isAbsolute()

Determines if the path is absolute.

public static isAbsolute(string $path) : bool
Parameters
$path : string
Return values
bool

joinPaths()

Joins all segments of the path and normalizes the result.

public static joinPaths(string ...$paths) : string
Parameters
$paths : string
Return values
string

makeWritable()

Sets file permissions to `$fileMode` or directory permissions to `$dirMode`.

public static makeWritable(string $path[, int $dirMode = 0777 ][, int $fileMode = 0666 ]) : void

Recursively traverses and sets permissions on the entire contents of the directory as well.

Parameters
$path : string
$dirMode : int = 0777
$fileMode : int = 0666
Tags
throws
IOException

on error occurred

normalizePath()

Normalizes `..` and `.` and directory separators in path.

public static normalizePath(string $path) : string
Parameters
$path : string
Return values
string

open()

Opens file and returns resource.

public static open(string $path, string $mode) : resource
Parameters
$path : string
$mode : string
Tags
throws
IOException

on error occurred

Return values
resource

platformSlashes()

Converts slashes to platform-specific directory separators.

public static platformSlashes(string $path) : string
Parameters
$path : string
Return values
string

read()

Reads the content of a file.

public static read(string $file) : string
Parameters
$file : string
Tags
throws
IOException

on error occurred

Return values
string

readLines()

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.

public static readLines(string $file[, bool $stripNewLines = true ]) : Generator<int, string>
Parameters
$file : string
$stripNewLines : bool = true
Tags
throws
IOException

on error occurred

Return values
Generator<int, string>

rename()

Renames or moves a file or a directory. Overwrites existing files and directories by default.

public static rename(string $origin, string $target[, bool $overwrite = true ]) : void
Parameters
$origin : string
$target : string
$overwrite : bool = true
Tags
throws
IOException

on error occurred

throws
InvalidStateException

if $overwrite is set to false and destination already exists

resolvePath()

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.

public static resolvePath(string $basePath, string $path) : string
Parameters
$basePath : string
$path : string
Return values
string

unixSlashes()

Converts backslashes to slashes.

public static unixSlashes(string $path) : string
Parameters
$path : string
Return values
string

write()

Writes the string to a file.

public static write(string $file, string $content[, int|null $mode = 0666 ]) : void
Parameters
$file : string
$content : string
$mode : int|null = 0666
Tags
throws
IOException

on error occurred


        
On this page

Search results