class Path (View source)

Cross-platform library for normalizing and joining file system paths.

Methods

static string
normalize(string $path, bool $prependDrive = true)

Normalizes the provided file system path.

static string
join(string[]|string $paths)

Joins the provided file systems paths together and normalizes the result.

Details

static string normalize(string $path, bool $prependDrive = true)

Normalizes the provided file system path.

Normalizing file system paths means that all forward and backward slashes in the path will be replaced with the system directory separator and multiple directory separators will be condensed into one. Additionally, all . and .. directory references will be resolved in the returned path.

Note that if the normalized path is not an absolute path, the resulting path may begin with .. directory references if it is not possible to resolve them simply by using string handling. You should also note that if the resulting path would result in an empty string, this method will return . instead.

If the $prependDrive option is enabled, the normalized path will be prepended with the drive name on Windows platforms using the current working directory, if the path is an absolute path that does not include a drive name.

Parameters

string $path File system path to normalize
bool $prependDrive True to prepend drive name to absolute paths

Return Value

string The normalizes file system path

static string join(string[]|string $paths)

Joins the provided file systems paths together and normalizes the result.

The paths can be provided either as multiple arguments to this method or as an array. The paths will be joined using the system directory separator and the result will be normalized similar to the normalization method (the drive letter will not be prepended however).

Note that unless the first path in the list is an absolute path, the entire resulting path will be treated as a relative path.

Parameters

string[]|string $paths File system paths to join

Return Value

string The joined file system paths