Documentation

Filesystem
in package

The part of symfony/filesystem the framework needs, with the signatures and the behavior of its Filesystem class for local files. The methods are static, PHP also accepts them on an instance: (new Filesystem())->remove($path) works like Filesystem::remove($path).

Table of Contents

copy()  : void
Copies one file with its permissions and its modification time. Missing parent directories of the target are created. An existing target is only replaced when the origin is newer, or always with $overwriteNewerFiles. A directory is copied with mirror().
mirror()  : void
Copies a directory with everything in it. Missing parent directories of the target are created, files are copied like with copy(), a link is copied as a link.
mkdir()  : void
Creates directories with every missing parent. A directory that already exists is left alone, also when another process creates it at the same moment.
remove()  : void
Removes files, links and directories with everything in them.
failure()  : RuntimeException
link()  : void
removeObsolete()  : void
removePath()  : void
toPaths()  : array<string|int, string>

Methods

copy()

Copies one file with its permissions and its modification time. Missing parent directories of the target are created. An existing target is only replaced when the origin is newer, or always with $overwriteNewerFiles. A directory is copied with mirror().

public static copy(string $originFile, string $targetFile[, bool $overwriteNewerFiles = false ]) : void
Parameters
$originFile : string
$targetFile : string
$overwriteNewerFiles : bool = false
Tags
throws
RuntimeException

When the origin is not a file or cannot be copied

Return values
void —

mirror()

Copies a directory with everything in it. Missing parent directories of the target are created, files are copied like with copy(), a link is copied as a link.

public static mirror(string $originDir, string $targetDir[, Traversable|null $iterator = null ][, array<string|int, mixed> $options = [] ]) : void
Parameters
$originDir : string
$targetDir : string
$iterator : Traversable|null = null

The entries to copy as SplFileInfo, by default everything in the origin

$options : array<string|int, mixed> = []

"override": replace files in the target that are newer than their origin (default false), "delete": remove what exists in the target but not in the origin (default false), "copy_on_windows": copy what a link points to instead of the link (default false)

Tags
throws
RuntimeException

When the origin is not a directory or an entry cannot be copied

Return values
void —

mkdir()

Creates directories with every missing parent. A directory that already exists is left alone, also when another process creates it at the same moment.

public static mkdir(string|iteratable<string|int, mixed> $dirs[, int $mode = 0777 ]) : void
Parameters
$dirs : string|iteratable<string|int, mixed>

One path or several

$mode : int = 0777

The permissions, lowered by the umask like with PHP's mkdir()

Tags
throws
RuntimeException

When a directory cannot be created

Return values
void —

remove()

Removes files, links and directories with everything in them.

public static remove(string|iteratable<string|int, mixed> $files) : void

A path that does not exist is left alone. A link is removed itself, its target is never touched.

Parameters
$files : string|iteratable<string|int, mixed>

One path or several

Tags
throws
RuntimeException

When an entry cannot be removed

Return values
void —

failure()

private static failure(string $action, string $path) : RuntimeException
Parameters
$action : string
$path : string
Return values
RuntimeException —
private static link(string $linkTarget, string $path) : void
Parameters
$linkTarget : string
$path : string
Return values
void —

removeObsolete()

private static removeObsolete(string $originDir, string $targetDir) : void
Parameters
$originDir : string
$targetDir : string
Return values
void —

removePath()

private static removePath(string $path) : void
Parameters
$path : string
Return values
void —

toPaths()

private static toPaths(string|iteratable<string|int, mixed> $paths) : array<string|int, string>
Parameters
$paths : string|iteratable<string|int, mixed>
Return values
array<string|int, string> —

Search results