A PHP library for computing relative paths.

Clone this repo:
  1. 59868d9 build: Updating mediawiki/mediawiki-codesniffer to 52.0.0 by libraryupgrader · 3 months ago master
  2. 790d34e Handle possible false from getcwd() in RelPath::getRelativePath by Umherirrender · 4 months ago
  3. 8277bf7 build: Updating mediawiki/mediawiki-codesniffer to 51.0.0 by libraryupgrader · 6 months ago
  4. 5a6e6fe Remove dead code for windows about root-relative start path by Umherirrender · 7 months ago
  5. d93907d tests: Add test for Unix-style absolute paths on Windows by Ori Livneh · 7 months ago

RelPath

RelPath is a small PHP library for working with file paths, to join two paths, or find the relative path to a path 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