Documentation

Filesystem
in package

Tags
author

Jordi Boggiano j.boggiano@seld.be

author

Johannes M. Schmitt schmittjoh@gmail.com

Table of Contents

$processExecutor  : mixed
__construct()  : mixed
copy()  : bool
Copies a file or directory from $source to $target.
copyThenRemove()  : mixed
Copy then delete is a non-atomic version of {@link rename}.
emptyDirectory()  : mixed
ensureDirectoryExists()  : mixed
findShortestPath()  : string
Returns the shortest path from $from to $to
findShortestPathCode()  : string
Returns PHP code that, when executed in $from, will return the path to $to
getPlatformPath()  : mixed
isAbsolutePath()  : bool
Checks if the given path is absolute
isDirEmpty()  : bool
Checks if a directory is empty
isJunction()  : bool
Returns whether the target directory is a Windows NTFS Junction.
isLocalPath()  : bool
Return if the given path is local
isSymlinkedDirectory()  : bool
return true if that directory is a symlink.
junction()  : mixed
Creates an NTFS junction.
normalizePath()  : string
Normalize a path. This replaces backslashes with slashes, removes ending slash and collapses redundant separators and up-level references.
relativeSymlink()  : bool
Creates a relative symlink from $link to $target
remove()  : mixed
removeDirectory()  : bool
Recursively remove a directory
removeDirectoryPhp()  : bool
Recursively delete directory using PHP iterators.
removeJunction()  : bool
Removes a Windows NTFS junction.
rename()  : mixed
rmdir()  : bool
Attempts to rmdir a file and in case of failure retries after 350ms on windows
size()  : int
Returns size of a file or directory specified by path. If a directory is given, it's size will be computed recursively.
unlink()  : bool
Attempts to unlink a file and in case of failure retries after 350ms on windows
directorySize()  : mixed
getProcess()  : mixed
resolveSymlinkedDirectorySymlink()  : string
resolve pathname to symbolic link of a directory
unlinkImplementation()  : bool
delete symbolic link implementation (commonly known as "unlink()")
unlinkSymlinkedDirectory()  : bool

Properties

Methods

copy()

Copies a file or directory from $source to $target.

public copy(string $source, string $target) : bool
Parameters
$source : string
$target : string
Return values
bool

copyThenRemove()

Copy then delete is a non-atomic version of {@link rename}.

public copyThenRemove(string $source, string $target) : mixed

Some systems can't rename and also don't have proc_open, which requires this solution.

Parameters
$source : string
$target : string
Return values
mixed

emptyDirectory()

public emptyDirectory(mixed $dir[, mixed $ensureDirectoryExists = true ]) : mixed
Parameters
$dir : mixed
$ensureDirectoryExists : mixed = true
Return values
mixed

ensureDirectoryExists()

public ensureDirectoryExists(mixed $directory) : mixed
Parameters
$directory : mixed
Return values
mixed

findShortestPath()

Returns the shortest path from $from to $to

public findShortestPath(string $from, string $to[, bool $directories = false ]) : string
Parameters
$from : string
$to : string
$directories : bool = false

if true, the source/target are considered to be directories

Tags
throws
InvalidArgumentException
Return values
string

findShortestPathCode()

Returns PHP code that, when executed in $from, will return the path to $to

public findShortestPathCode(string $from, string $to[, bool $directories = false ][, bool $staticCode = false ]) : string
Parameters
$from : string
$to : string
$directories : bool = false

if true, the source/target are considered to be directories

$staticCode : bool = false
Tags
throws
InvalidArgumentException
Return values
string

getPlatformPath()

public static getPlatformPath(mixed $path) : mixed
Parameters
$path : mixed
Return values
mixed

isAbsolutePath()

Checks if the given path is absolute

public isAbsolutePath(string $path) : bool
Parameters
$path : string
Return values
bool

isDirEmpty()

Checks if a directory is empty

public isDirEmpty(string $dir) : bool
Parameters
$dir : string
Return values
bool

isJunction()

Returns whether the target directory is a Windows NTFS Junction.

public isJunction(string $junction) : bool

We test if the path is a directory and not an ordinary link, then check that the mode value returned from lstat (which gives the status of the link itself) is not a directory, by replicating the POSIX S_ISDIR test.

This logic works because PHP does not set the mode value for a junction, since there is no universal file type flag for it. Unfortunately an uninitialized variable in PHP prior to 7.2.16 and 7.3.3 may cause a random value to be returned. See https://bugs.php.net/bug.php?id=77552

If this random value passes the S_ISDIR test, then a junction will not be detected and a recursive delete operation could lead to loss of data in the target directory. Note that Windows rmdir can handle this situation and will only delete the junction (from Windows 7 onwards).

Parameters
$junction : string

Path to check.

Return values
bool

isLocalPath()

Return if the given path is local

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

isSymlinkedDirectory()

return true if that directory is a symlink.

public isSymlinkedDirectory(string $directory) : bool
Parameters
$directory : string
Return values
bool

junction()

Creates an NTFS junction.

public junction(string $target, string $junction) : mixed
Parameters
$target : string
$junction : string
Return values
mixed

normalizePath()

Normalize a path. This replaces backslashes with slashes, removes ending slash and collapses redundant separators and up-level references.

public normalizePath(string $path) : string
Parameters
$path : string

Path to the file or directory

Return values
string

Creates a relative symlink from $link to $target

public relativeSymlink(string $target, string $link) : bool
Parameters
$target : string

The path of the binary file to be symlinked

$link : string

The path where the symlink should be created

Return values
bool

remove()

public remove(mixed $file) : mixed
Parameters
$file : mixed
Return values
mixed

removeDirectory()

Recursively remove a directory

public removeDirectory(string $directory) : bool

Uses the process component if proc_open is enabled on the PHP installation.

Parameters
$directory : string
Tags
throws
RuntimeException
Return values
bool

removeDirectoryPhp()

Recursively delete directory using PHP iterators.

public removeDirectoryPhp(string $directory) : bool

Uses a CHILD_FIRST RecursiveIteratorIterator to sort files before directories, creating a single non-recursive loop to delete files/directories in the correct order.

Parameters
$directory : string
Return values
bool

removeJunction()

Removes a Windows NTFS junction.

public removeJunction(string $junction) : bool
Parameters
$junction : string
Return values
bool

rename()

public rename(mixed $source, mixed $target) : mixed
Parameters
$source : mixed
$target : mixed
Return values
mixed

rmdir()

Attempts to rmdir a file and in case of failure retries after 350ms on windows

public rmdir(string $path) : bool
Parameters
$path : string
Tags
throws
RuntimeException
Return values
bool

size()

Returns size of a file or directory specified by path. If a directory is given, it's size will be computed recursively.

public size(string $path) : int
Parameters
$path : string

Path to the file or directory

Tags
throws
RuntimeException
Return values
int

Attempts to unlink a file and in case of failure retries after 350ms on windows

public unlink(string $path) : bool
Parameters
$path : string
Tags
throws
RuntimeException
Return values
bool

directorySize()

protected directorySize(mixed $directory) : mixed
Parameters
$directory : mixed
Return values
mixed

getProcess()

protected getProcess() : mixed
Return values
mixed

resolve pathname to symbolic link of a directory

private resolveSymlinkedDirectorySymlink(string $pathname) : string
Parameters
$pathname : string

directory path to resolve

Return values
string

resolved path to symbolic link or original pathname (unresolved)

unlinkImplementation()

delete symbolic link implementation (commonly known as "unlink()")

private unlinkImplementation(string $path) : bool

symbolic links on windows which link to directories need rmdir instead of unlink

Parameters
$path : string
Return values
bool

unlinkSymlinkedDirectory()

private unlinkSymlinkedDirectory(string $directory) : bool
Parameters
$directory : string
Return values
bool

Search results