RelPath
Work with file paths to join or find the relative path
Loading...
Searching...
No Matches
Wikimedia\RelPath Class Reference

Utilities for computing a relative filepath between two paths. More...

Static Public Member Functions

static splitPath (string $path)
 Split a path into path components.
 
static getRelativePath (string $path, ?string $start=null)
 Return a relative filepath to $path, either from the current directory or from an optional start directory.
 
static joinPath (string $base, string $path)
 Join two path components.
 

Detailed Description

Utilities for computing a relative filepath between two paths.

Member Function Documentation

◆ getRelativePath()

static Wikimedia\RelPath::getRelativePath ( string $path,
?string $start = null )
static

Return a relative filepath to $path, either from the current directory or from an optional start directory.

Both paths must be absolute.

Parameters
string$pathFile path.
string | null$startStart directory. Optional; if not specified, the current working directory will be used.
Returns
string|false Relative path, or false if input was invalid.

◆ joinPath()

static Wikimedia\RelPath::joinPath ( string $base,
string $path )
static

Join two path components.

This can be used to expand a path relative to a given base path. The given path may also be absolute, in which case it is returned directly.

RelPath::joinPath('/srv/foo', 'bar'); # '/srv/foo/bar'
RelPath::joinPath('/srv/foo', './bar'); # '/srv/foo/bar'
RelPath::joinPath('/srv//foo', '../baz'); # '/srv/baz'
RelPath::joinPath('/srv/foo', '/var/quux/'); # '/var/quux/'

This function is similar to os.path.join() in Python, and path.join() in Node.js.

Parameters
string$baseBase path.
string$pathFile $path to join to $base path.
Returns
string|false Combined path, or false if input was invalid.

◆ splitPath()

static Wikimedia\RelPath::splitPath ( string $path)
static

Split a path into path components.

Parameters
string$pathFile path.
Returns
string[] Array of path components.

The documentation for this class was generated from the following file: