class Path (View source)

A Path handling class

Methods

static boolean
canChmod(string $path)

Checks if a path's permissions can be changed.

static boolean
setPermissions(string $path, string $filemode = '0644', string $foldermode = '0755')

Chmods files and directories recursively to given permissions.

static string
getPermissions(string $path, boolean $toString = false)

Get the permissions of the file/folder at a give path.

static string
check(string $path, string $root)

Checks for snooping outside of the file system root.

static string
clean(string $path, string $ds = DIRECTORY_SEPARATOR)

Function to strip additional / or \ in a path name.

static string
normalize(string $path, string $ds = DIRECTORY_SEPARATOR)

Normalize a path. This method will do clean() first to replace slashes and remove '.

static mixed
find(mixed $paths, string $file)

Searches the directory paths for a given file.

Details

at line line 29
static boolean canChmod(string $path)

Checks if a path's permissions can be changed.

Parameters

string $path Path to check.

Return Value

boolean True if path can have mode changed.

at line line 57
static boolean setPermissions(string $path, string $filemode = '0644', string $foldermode = '0755')

Chmods files and directories recursively to given permissions.

Parameters

string $path Root path to begin changing mode [without trailing slash].
string $filemode Octal representation of the value to change file mode to [null = no change].
string $foldermode Octal representation of the value to change folder mode to [null = no change].

Return Value

boolean True if successful [one fail means the whole operation failed].

at line line 123
static string getPermissions(string $path, boolean $toString = false)

Get the permissions of the file/folder at a give path.

Parameters

string $path The path of a file/folder.
boolean $toString Convert permission number to string.

Return Value

string Filesystem permissions.

at line line 166
static string check(string $path, string $root)

Checks for snooping outside of the file system root.

Parameters

string $path A file system path to check.
string $root System root path.

Return Value

string A cleaned version of the path or exit on error.

Exceptions

Exception

at line line 194
static string clean(string $path, string $ds = DIRECTORY_SEPARATOR)

Function to strip additional / or \ in a path name.

Parameters

string $path The path to clean.
string $ds Directory separator (optional).

Return Value

string The cleaned path.

Exceptions

UnexpectedValueException If $path is not a string.

at line line 229
static string normalize(string $path, string $ds = DIRECTORY_SEPARATOR)

Normalize a path. This method will do clean() first to replace slashes and remove '.

.' to create a Clean path. Unlike realpath(), if this path not exists, normalise() will still return this path.

Parameters

string $path The path to normalize.
string $ds Directory separator (optional).

Return Value

string The normalized path.

Exceptions

UnexpectedValueException If $path is not a string.

at line line 278
static mixed find(mixed $paths, string $file)

Searches the directory paths for a given file.

Parameters

mixed $paths An path string or array of path strings to search in
string $file The file name to look for.

Return Value

mixed The full path and file name for the target file, or boolean false if the file is not found in any of the paths.