Utilities for computing a relative filepath between two paths.
More...
|
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.
|
|
Utilities for computing a relative filepath between two paths.
◆ 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 | $path | File path. |
string | null | $start | Start 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 | $base | Base path. |
string | $path | File $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
-
- Returns
- string[] Array of path components.
The documentation for this class was generated from the following file: