Filesystem
in package
Provides basic utility to manipulate the file system.
Tags
Table of Contents
- $lastError : mixed
- appendToFile() : mixed
- Appends content to an existing file.
- chgrp() : mixed
- Change the group of an array of files or directories.
- chmod() : mixed
- Change mode for an array of files or directories.
- chown() : mixed
- Change the owner of an array of files or directories.
- copy() : mixed
- Copies a file.
- dumpFile() : mixed
- Atomically dumps content into a file.
- exists() : bool
- Checks the existence of files or directories.
- hardlink() : mixed
- Creates a hard link, or several hard links to a file.
- isAbsolutePath() : bool
- Returns whether the file path is an absolute path.
- makePathRelative() : string
- Given an existing path, convert it to a path relative to a given starting path.
- mirror() : mixed
- Mirrors a directory to another.
- mkdir() : mixed
- Creates a directory recursively.
- readlink() : string|null
- Resolves links in paths.
- remove() : mixed
- Removes files or directories.
- rename() : mixed
- Renames a file or a directory.
- symlink() : mixed
- Creates a symbolic link or copy a directory.
- tempnam() : string
- Creates a temporary file with support for custom stream wrappers.
- touch() : mixed
- Sets access and modification time of file.
- assertFunctionExists() : void
- box() : mixed
- doRemove() : void
- getSchemeAndHierarchy() : array<string|int, mixed>
- Gets a 2-tuple of scheme (may be null) and hierarchical part of a filename (e.g. file:///tmp -> [file, tmp]).
- isReadable() : bool
- Tells whether a file exists and is readable.
- linkException() : mixed
- toIterable() : iteratable<string|int, mixed>
Properties
$lastError
private
static mixed
$lastError
Methods
appendToFile()
Appends content to an existing file.
public
appendToFile(string $filename, string|resource $content) : mixed
Parameters
- $filename : string
- $content : string|resource
-
The content to append
Tags
Return values
mixed —chgrp()
Change the group of an array of files or directories.
public
chgrp(string|iteratable<string|int, mixed> $files, string|int $group[, bool $recursive = false ]) : mixed
Parameters
- $files : string|iteratable<string|int, mixed>
-
A filename, an array of files, or a \Traversable instance to change group
- $group : string|int
-
A group name or number
- $recursive : bool = false
-
Whether change the group recursively or not
Tags
Return values
mixed —chmod()
Change mode for an array of files or directories.
public
chmod(string|iteratable<string|int, mixed> $files, int $mode[, int $umask = 00 ][, bool $recursive = false ]) : mixed
Parameters
- $files : string|iteratable<string|int, mixed>
-
A filename, an array of files, or a \Traversable instance to change mode
- $mode : int
-
The new mode (octal)
- $umask : int = 00
-
The mode mask (octal)
- $recursive : bool = false
-
Whether change the mod recursively or not
Tags
Return values
mixed —chown()
Change the owner of an array of files or directories.
public
chown(string|iteratable<string|int, mixed> $files, string|int $user[, bool $recursive = false ]) : mixed
Parameters
- $files : string|iteratable<string|int, mixed>
-
A filename, an array of files, or a \Traversable instance to change owner
- $user : string|int
-
A user name or number
- $recursive : bool = false
-
Whether change the owner recursively or not
Tags
Return values
mixed —copy()
Copies a file.
public
copy(string $originFile, string $targetFile[, bool $overwriteNewerFiles = false ]) : mixed
If the target file is older than the origin file, it's always overwritten. If the target file is newer, it is overwritten only when the $overwriteNewerFiles option is set to true.
Parameters
- $originFile : string
- $targetFile : string
- $overwriteNewerFiles : bool = false
Tags
Return values
mixed —dumpFile()
Atomically dumps content into a file.
public
dumpFile(string $filename, string|resource $content) : mixed
Parameters
- $filename : string
- $content : string|resource
-
The data to write into the file
Tags
Return values
mixed —exists()
Checks the existence of files or directories.
public
exists(string|iteratable<string|int, mixed> $files) : bool
Parameters
- $files : string|iteratable<string|int, mixed>
-
A filename, an array of files, or a \Traversable instance to check
Return values
bool —hardlink()
Creates a hard link, or several hard links to a file.
public
hardlink(string $originFile, string|array<string|int, string> $targetFiles) : mixed
Parameters
- $originFile : string
- $targetFiles : string|array<string|int, string>
-
The target file(s)
Tags
Return values
mixed —isAbsolutePath()
Returns whether the file path is an absolute path.
public
isAbsolutePath(string $file) : bool
Parameters
- $file : string
Return values
bool —makePathRelative()
Given an existing path, convert it to a path relative to a given starting path.
public
makePathRelative(string $endPath, string $startPath) : string
Parameters
- $endPath : string
- $startPath : string
Return values
string —mirror()
Mirrors a directory to another.
public
mirror(string $originDir, string $targetDir[, Traversable|null $iterator = null ][, array<string|int, mixed> $options = [] ]) : mixed
Copies files and directories from the origin directory into the target directory. By default:
- existing files in the target directory will be overwritten, except if they are newer (see the
override
option) - files in the target directory that do not exist in the source directory will not be deleted (see the
delete
option)
Parameters
- $originDir : string
- $targetDir : string
- $iterator : Traversable|null = null
-
Iterator that filters which files and directories to copy, if null a recursive iterator is created
- $options : array<string|int, mixed> = []
-
An array of boolean options Valid options are:
- $options['override'] If true, target files newer than origin files are overwritten (see copy(), defaults to false)
- $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink(), defaults to false)
- $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
Tags
Return values
mixed —mkdir()
Creates a directory recursively.
public
mkdir(string|iteratable<string|int, mixed> $dirs[, int $mode = 0777 ]) : mixed
Parameters
- $dirs : string|iteratable<string|int, mixed>
-
The directory path
- $mode : int = 0777
Tags
Return values
mixed —readlink()
Resolves links in paths.
public
readlink(string $path[, bool $canonicalize = false ]) : string|null
With $canonicalize = false (default) - if $path does not exist or is not a link, returns null - if $path is a link, returns the next direct target of the link without considering the existence of the target
With $canonicalize = true - if $path does not exist, returns null - if $path exists, returns its absolute fully resolved final version
Parameters
- $path : string
- $canonicalize : bool = false
Return values
string|null —remove()
Removes files or directories.
public
remove(string|iteratable<string|int, mixed> $files) : mixed
Parameters
- $files : string|iteratable<string|int, mixed>
-
A filename, an array of files, or a \Traversable instance to remove
Tags
Return values
mixed —rename()
Renames a file or a directory.
public
rename(string $origin, string $target[, bool $overwrite = false ]) : mixed
Parameters
- $origin : string
- $target : string
- $overwrite : bool = false
Tags
Return values
mixed —symlink()
Creates a symbolic link or copy a directory.
public
symlink(string $originDir, string $targetDir[, bool $copyOnWindows = false ]) : mixed
Parameters
- $originDir : string
- $targetDir : string
- $copyOnWindows : bool = false
Tags
Return values
mixed —tempnam()
Creates a temporary file with support for custom stream wrappers.
public
tempnam(string $dir, string $prefix) : string
Parameters
- $dir : string
- $prefix : string
-
The prefix of the generated temporary filename Note: Windows uses only the first three characters of prefix
Return values
string —The new temporary filename (with path), or throw an exception on failure
touch()
Sets access and modification time of file.
public
touch(string|iteratable<string|int, mixed> $files[, int|null $time = null ][, int|null $atime = null ]) : mixed
Parameters
- $files : string|iteratable<string|int, mixed>
-
A filename, an array of files, or a \Traversable instance to create
- $time : int|null = null
-
The touch time as a Unix timestamp, if not supplied the current system time is used
- $atime : int|null = null
-
The access time as a Unix timestamp, if not supplied the current system time is used
Tags
Return values
mixed —assertFunctionExists()
private
static assertFunctionExists(string $func) : void
Parameters
- $func : string
Return values
void —box()
private
static box(string $func, mixed ...$args) : mixed
Parameters
- $func : string
- $args : mixed
Return values
mixed —doRemove()
private
static doRemove(array<string|int, mixed> $files, bool $isRecursive) : void
Parameters
- $files : array<string|int, mixed>
- $isRecursive : bool
Return values
void —getSchemeAndHierarchy()
Gets a 2-tuple of scheme (may be null) and hierarchical part of a filename (e.g. file:///tmp -> [file, tmp]).
private
getSchemeAndHierarchy(string $filename) : array<string|int, mixed>
Parameters
- $filename : string
Return values
array<string|int, mixed> —isReadable()
Tells whether a file exists and is readable.
private
isReadable(string $filename) : bool
Parameters
- $filename : string
Tags
Return values
bool —linkException()
private
linkException(string $origin, string $target, string $linkType) : mixed
Parameters
- $origin : string
- $target : string
- $linkType : string
-
Name of the link type, typically 'symbolic' or 'hard'
Return values
mixed —toIterable()
private
toIterable(mixed $files) : iteratable<string|int, mixed>
Parameters
- $files : mixed