wikimedia/relpath

Compute a relative filepath between two paths.

3.0.0 2021-08-03 16:57 UTC

This package is auto-updated.

Last update: 2021-10-03 17:32:30 UTC


README

RelPath is a small PHP library for computing a relative filepath to some path, either from the current directory or from an optional start directory.

Here is how you use it:

$relPath = \Wikimedia\RelPath::getRelativePath( '/srv/mediawiki/resources/src/startup.js', '/srv/mediawiki' );
// Result: "resources/src/startup.js"

$fullPath = \Wikimedia\RelPath::joinPath( '/srv/mediawiki', 'resources/src/startup.js' );
// Result: "/srv/mediawiki/resources/src/startup.js"

$fullPath = \Wikimedia\RelPath::joinPath( '/srv/mediawiki', '/var/startup/startup.js' );
// Result: "/var/startup/startup.js"

The RelPath::joinPath() function provided here is analogous to os.path.join() in Python, and path.join() found in Node.js.

License

MIT