Composer API
Class

Composer\Util\Filesystem

class Filesystem

Methods

__construct(ProcessExecutor $executor = null)

remove($file)

bool isDirEmpty(string $dir)

Checks if a directory is empty

emptyDirectory($dir, $ensureDirectoryExists = true)

bool removeDirectory(string $directory)

Recursively remove a directory

bool removeDirectoryPhp(string $directory)

Recursively delete directory using PHP iterators.

ensureDirectoryExists($directory)

bool unlink(string $path)

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

bool rmdir(string $path)

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

copyThenRemove(string $source, string $target)

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

bool copy($source $source, $target $target)

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

rename($source, $target)

string findShortestPath(string $from, string $to, bool $directories = false)

Returns the shortest path from $from to $to

string findShortestPathCode(string $from, string $to, bool $directories = false, bool $staticCode = false)

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

bool isAbsolutePath(string $path)

Checks if the given path is absolute

int size(string $path)

Returns size of a file or directory specified by path.

string normalizePath(string $path)

Normalize a path.

static bool isLocalPath(string $path)

Return if the given path is local

static  getPlatformPath($path)

bool relativeSymlink(string $target, string $link)

Creates a relative symlink from $link to $target

bool isSymlinkedDirectory(string $directory)

return true if that directory is a symlink.

junction(string $target, string $junction)

Creates an NTFS junction.

bool isJunction(string $junction)

Returns whether the target directory is a Windows NTFS Junction.

bool removeJunction(string $junction)

Removes a Windows NTFS junction.

Details

at line 28
public __construct(ProcessExecutor $executor = null)

Parameters

ProcessExecutor $executor

at line 33
public remove($file)

Parameters

$file

at line 52
public bool isDirEmpty(string $dir)

Checks if a directory is empty

Parameters

string $dir

Return Value

bool

at line 63
public emptyDirectory($dir, $ensureDirectoryExists = true)

Parameters

$dir
$ensureDirectoryExists

at line 96
public bool removeDirectory(string $directory)

Recursively remove a directory

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

Parameters

string $directory

Return Value

bool

Exceptions

RuntimeException

at line 146
public bool removeDirectoryPhp(string $directory)

Recursively delete directory using PHP iterators.

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

string $directory

Return Value

bool

at line 173
public ensureDirectoryExists($directory)

Parameters

$directory

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

Parameters

string $path

Return Value

bool

Exceptions

RuntimeException

at line 221
public bool rmdir(string $path)

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

Parameters

string $path

Return Value

bool

Exceptions

RuntimeException

at line 248
public copyThenRemove(string $source, string $target)

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

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

Parameters

string $source
string $target

at line 267
public bool copy($source $source, $target $target)

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

Parameters

$source $source
$target $target

Return Value

bool

at line 289
public rename($source, $target)

Parameters

$source
$target

at line 338
public string findShortestPath(string $from, string $to, bool $directories = false)

Returns the shortest path from $from to $to

Parameters

string $from
string $to
bool $directories if true, the source/target are considered to be directories

Return Value

string

Exceptions

InvalidArgumentException

at line 381
public string findShortestPathCode(string $from, string $to, bool $directories = false, bool $staticCode = false)

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

Parameters

string $from
string $to
bool $directories if true, the source/target are considered to be directories
bool $staticCode

Return Value

string

Exceptions

InvalidArgumentException

at line 424
public bool isAbsolutePath(string $path)

Checks if the given path is absolute

Parameters

string $path

Return Value

bool

at line 437
public int size(string $path)

Returns size of a file or directory specified by path.

If a directory is given, it's size will be computed recursively.

Parameters

string $path Path to the file or directory

Return Value

int

Exceptions

RuntimeException

at line 456
public string normalizePath(string $path)

Normalize a path.

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

Parameters

string $path Path to the file or directory

Return Value

string

at line 494
static public bool isLocalPath(string $path)

Return if the given path is local

Parameters

string $path

Return Value

bool

at line 499
static public getPlatformPath($path)

Parameters

$path

Creates a relative symlink from $link to $target

Parameters

string $target The path of the binary file to be symlinked
string $link The path where the symlink should be created

Return Value

bool

at line 573
public bool isSymlinkedDirectory(string $directory)

return true if that directory is a symlink.

Parameters

string $directory

Return Value

bool

at line 624
public junction(string $target, string $junction)

Creates an NTFS junction.

Parameters

string $target
string $junction

at line 647
public bool isJunction(string $junction)

Returns whether the target directory is a Windows NTFS Junction.

Parameters

string $junction Path to check.

Return Value

bool

at line 678
public bool removeJunction(string $junction)

Removes a Windows NTFS junction.

Parameters

string $junction

Return Value

bool