Filesystem

Class
extends Filesystem
implements FilesystemInterface
Final: Yes

Concrete implementation of the standard filesystem interface.

Description

This class wraps over the Symfony Filesystem component, automatically converting provided paths to absolute representations when a base path is supplied or dynamically inferred from the generic working directory.

Table of Contents

Interfaces

FilesystemInterface

Defines a standard file system interface with enhanced path resolution.

Methods

basename()

Returns the trailing name component of a path.

 : string
chmod()

Changes the permission mode for one or more files.

 : void
copy()

Copies a file to a target path.

 : void
dirname()

Returns a parent directory's path.

 : string
dumpFile()

Writes content to a file, overriding it if it already exists.

 : void
exists()

Checks whether a file or directory exists.

 : bool
getAbsolutePath()

Resolves a path or iterable of paths into their absolute path representation.

 : iterable<string|int, string>|string
makePathRelative()

Computes the relative path from the base path to the target path.

 : string
mkdir()

Creates a directory recursively.

 : void
readFile()

Reads the entire content of a file.

 : string
readlink()

Reads a symbolic link target.

 : string|null
remove()

Removes files, symbolic links, or directories.

 : void
symlink()

Creates a symbolic link.

 : void
Methods

basename()

Public

Returns the trailing name component of a path.

public basename( 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
string

Description

the base name of the given path

chmod()

Public

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

Attributes
#[Override]

copy()

Public

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

Attributes
#[Override]

dirname()

Public

Returns a parent directory's path.

public dirname( 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
string

Description

the parent path name

dumpFile()

Public

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

Attributes
#[Override]

exists()

Public

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

Attributes
#[Override]
Return values
bool

Description

true if the path exists, false otherwise

getAbsolutePath()

Public

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
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
iterable<string|int, string>|string

Description

the resolved absolute path(s)

makePathRelative()

Public

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

Attributes
#[Override]
Return values
string

Description

the computed relative path

mkdir()

Public

Creates a directory recursively.

public mkdir( iterable<string|int, string>|string  $dirs[, int  $mode = 0777][, string|null  $basePath = null]) : 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)

$basePath : string|null = null

Description

the base path for relative path resolution

Attributes
#[Override]

readFile()

Public

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

Attributes
#[Override]
Return values
string

Description

the content of the file

Public

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

Attributes
#[Override]
Return values
string|null

Description

the link target, or null when the path is not a symbolic link

remove()

Public

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

Attributes
#[Override]
Public

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

Attributes
#[Override]