class Filesystem

Provides basic utility to manipulate the file system.

Methods

copy(string $originFile, string $targetFile, boolean $override = false)

Copies a file.

mkdir(string|array|Traversable $dirs, integer $mode = 511)

Creates a directory recursively.

Boolean
exists(string|array|Traversable $files)

Checks the existence of files or directories.

touch(string|array|Traversable $files, integer $time = null, integer $atime = null)

Sets access and modification time of file.

remove(string|array|Traversable $files)

Removes files or directories.

chmod(string|array|Traversable $files, integer $mode, integer $umask, Boolean $recursive = false)

Change mode for an array of files or directories.

chown(string|array|Traversable $files, string $user, Boolean $recursive = false)

Change the owner of an array of files or directories

chgrp(string|array|Traversable $files, string $group, Boolean $recursive = false)

Change the group of an array of files or directories

rename(string $origin, string $target, Boolean $overwrite = false)

Renames a file or a directory.

symlink(string $originDir, string $targetDir, Boolean $copyOnWindows = false)

Creates a symbolic link or copy a directory.

string
makePathRelative(string $endPath, string $startPath)

Given an existing path, convert it to a path relative to a given starting path

mirror(string $originDir, string $targetDir, Traversable $iterator = null, array $options = array())

Mirrors a directory to another.

Boolean
isAbsolutePath(string $file)

Returns whether the file path is an absolute path.

dumpFile(string $filename, string $content, integer $mode = 438)

Atomically dumps content into a file.

Details

at line line 36
copy(string $originFile, string $targetFile, boolean $override = false)

Copies a file.

This method only copies the file if the origin file is newer than the target file.

By default, if the target already exists, it is not overridden.

Parameters

string $originFile The original filename
string $targetFile The target filename
boolean $override Whether to override an existing file or not

Exceptions

IOException When copy fails

at line line 73
mkdir(string|array|Traversable $dirs, integer $mode = 511)

Creates a directory recursively.

Parameters

string|array|Traversable $dirs The directory path
integer $mode The directory mode

Exceptions

IOException On any directory creation failure

at line line 93
Boolean exists(string|array|Traversable $files)

Checks the existence of files or directories.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to check

Return Value

Boolean true if the file exists, false otherwise

at line line 113
touch(string|array|Traversable $files, integer $time = null, integer $atime = null)

Sets access and modification time of file.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to create
integer $time The touch time as a Unix timestamp
integer $atime The access time as a Unix timestamp

Exceptions

IOException When touch fails

at line line 130
remove(string|array|Traversable $files)

Removes files or directories.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to remove

Exceptions

IOException When removal fails

at line line 170
chmod(string|array|Traversable $files, integer $mode, integer $umask, Boolean $recursive = false)

Change mode for an array of files or directories.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to change mode
integer $mode The new mode (octal)
integer $umask The mode mask (octal)
Boolean $recursive Whether change the mod recursively or not

Exceptions

IOException When the change fail

at line line 191
chown(string|array|Traversable $files, string $user, Boolean $recursive = false)

Change the owner of an array of files or directories

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to change owner
string $user The new owner user name
Boolean $recursive Whether change the owner recursively or not

Exceptions

IOException When the change fail

at line line 218
chgrp(string|array|Traversable $files, string $group, Boolean $recursive = false)

Change the group of an array of files or directories

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to change group
string $group The group name
Boolean $recursive Whether change the group recursively or not

Exceptions

IOException When the change fail

at line line 246
rename(string $origin, string $target, Boolean $overwrite = false)

Renames a file or a directory.

Parameters

string $origin The origin filename or directory
string $target The new filename or directory
Boolean $overwrite Whether to overwrite the target if it already exists

Exceptions

IOException When target file or directory already exists
IOException When origin cannot be renamed

Creates a symbolic link or copy a directory.

Parameters

string $originDir The origin directory path
string $targetDir The symbolic link name
Boolean $copyOnWindows Whether to copy files if on Windows

Exceptions

IOException When symlink fails

at line line 307
string makePathRelative(string $endPath, string $startPath)

Given an existing path, convert it to a path relative to a given starting path

Parameters

string $endPath Absolute path of target
string $startPath Absolute path where traversal begins

Return Value

string Path of target relative to starting path

at line line 353
mirror(string $originDir, string $targetDir, Traversable $iterator = null, array $options = array())

Mirrors a directory to another.

Parameters

string $originDir The origin directory
string $targetDir The target directory
Traversable $iterator A Traversable instance
array $options An array of boolean options Valid options are: - $options['override'] Whether to override an existing file on copy or not (see copy()) - $options['copyonwindows'] Whether to copy files instead of links on Windows (see symlink()) - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)

Exceptions

IOException When file type is unknown

at line line 415
Boolean isAbsolutePath(string $file)

Returns whether the file path is an absolute path.

Parameters

string $file A file path

Return Value

Boolean

at line line 452
dumpFile(string $filename, string $content, integer $mode = 438)

Atomically dumps content into a file.

Parameters

string $filename The file to be written to.
string $content The data to write into the file.
integer $mode The file mode (octal).

Exceptions

IOException If the file cannot be written to.