FilesystemInterface
Defines a standard file system interface with enhanced path resolution.
Description
This interface extends common filesystem operations by ensuring paths can be deterministically resolved to absolute paths before interaction.
Methods
Changes the permission mode for one or more files.
Copies a file to a target path.
Writes content to a file, overriding it if it already exists.
Checks whether a file or directory exists.
Resolves a path or iterable of paths into their absolute path representation.
Returns the trailing name component of a path.
Returns a parent directory's path.
Computes the relative path from the base path to the target path.
Creates a directory recursively.
Reads the entire content of a file.
Reads a symbolic link target.
Removes files, symbolic links, or directories.
Creates a symbolic link.
Changes the permission mode for one or more files.
public
chmod(
iterable<string|int, string>|string
$files,
int
$mode[,
int
$umask = 00][,
bool
$recursive = false]) : void
Parameters
$files
:
iterable<string|int, string>|string
Description
the target file paths
$mode
:
int
Description
the permission mode to apply
$umask
:
int
=
00
Description
the umask to apply
$recursive
:
bool
=
false
Description
whether permissions SHOULD be applied recursively
Copies a file to a target path.
public
copy(
string
$originFile,
string
$targetFile[,
bool
$overwriteNewerFiles = false]) : void
Parameters
$originFile
:
string
Description
the source file path to copy
$targetFile
:
string
Description
the target file path to create
$overwriteNewerFiles
:
bool
=
false
Description
whether newer target files MAY be overwritten
Writes content to a file, overriding it if it already exists.
public
dumpFile(
string
$filename,
mixed
$content[,
string|null
$path = null]) : void
Parameters
$filename
:
string
Description
the filename to write to
$content
:
mixed
Description
the content to write
$path
:
string|null
=
null
Description
the optional base path to resolve the filename against
Checks whether a file or directory exists.
public
exists(
iterable<string|int, string>|string
$files[,
string|null
$basePath = null]) : bool
Parameters
$files
:
iterable<string|int, string>|string
Description
the file(s) or directory(ies) to check
$basePath
:
string|null
=
null
Description
the base path used to resolve relative paths
Return values
Description
true if the path exists, false otherwise
Resolves a path or iterable of paths into their absolute path representation.
public
getAbsolutePath(
iterable<string|int, string>|string
$files[,
string|null
$basePath = null]) : iterable<string|int, string>|string
Description
If a relative path is provided, it SHALL be evaluated against the current working directory or the provided $basePath if one is supplied.
Parameters
$files
:
iterable<string|int, string>|string
Description
the path(s) to resolve
$basePath
:
string|null
=
null
Description
the base path for relative path resolution
Return values
Description
the resolved absolute path(s)
Returns the trailing name component of a path.
public
getBasename(
string
$path[,
string
$suffix = '']) : string
Parameters
$path
:
string
Description
the path to process
$suffix
:
string
=
''
Description
an optional suffix to strip from the returned basename
Return values
Description
the base name of the given path
Returns a parent directory's path.
public
getDirectory(
string
$path[,
int
$levels = 1]) : string
Parameters
$path
:
string
Description
the path to evaluate
$levels
:
int
=
1
Description
the number of parent directories to go up
Return values
Description
the parent path name
Computes the relative path from the base path to the target path.
public
makePathRelative(
string
$path[,
string|null
$basePath = null]) : string
Parameters
$path
:
string
Description
the target absolute or relative path
$basePath
:
string|null
=
null
Description
the origin point; defaults to the current working directory
Return values
Description
the computed relative path
Creates a directory recursively.
public
mkdir(
iterable<string|int, string>|string
$dirs[,
int
$mode = 0777]) : void
Parameters
$dirs
:
iterable<string|int, string>|string
Description
the directory path(s) to create
$mode
:
int
=
0777
Description
the permissions mode (defaults to 0777)
Reads the entire content of a file.
public
readFile(
string
$filename[,
string|null
$path = null]) : string
Parameters
$filename
:
string
Description
the target filename to read
$path
:
string|null
=
null
Description
the optional base path to resolve the filename against
Return values
Description
the content of the file
Reads a symbolic link target.
public
readlink(
string
$path[,
bool
$canonicalize = false]) : string|null
Parameters
$path
:
string
Description
the symbolic link path
$canonicalize
:
bool
=
false
Description
whether the returned path SHOULD be canonicalized
Return values
Description
the link target, or null when the path is not a symbolic link
Removes files, symbolic links, or directories.
public
remove(
iterable<string|int, string>|string
$files) : void
Parameters
$files
:
iterable<string|int, string>|string
Description
the file(s), link(s), or directory(ies) to remove
Creates a symbolic link.
public
symlink(
string
$originDir,
string
$targetDir[,
bool
$copyOnWindows = false]) : void
Parameters
$originDir
:
string
Description
the origin path the link MUST point to
$targetDir
:
string
Description
the link path to create
$copyOnWindows
:
bool
=
false
Description
whether directories SHOULD be copied on Windows instead of linked