path
PHP 5.4 port of the node/iojs path module, because PHP is like a family holiday dinner and I want to survive. Description from the iojs documentation:, (*1)
This module contains utilities for handling and transforming file paths. Almost all these methods perform only string transformations. The file system is not consulted to check whether paths are valid., (*2)
, (*3)
Jump to: usage / install / license, (*4)
examples
Example output on a posix system, assuming "/please" is the current working directory:, (*5)
usage
Usage docs pending. In the meantime, consult the iojs documentation, because the function signatures are almost the same and the code (including unit tests) copied., (*6)
Ported so far (for posix and windows), including unit tests
relative($from, $to)
isAbsolute($path)
resolve($path, ..)
join($path, ..)
normalize($path)
separator()
delimiter()
PHP-specific additions
resolve()
also accepts stream wrapper URI's. This is implemented outside of the (ported) posix and Windows adapters, to ensure it doesn't interfere with the original behavior (which remains well tested and has a frozen stability)., (*7)
-
file
schemes are stripped, unless combined with other schemes
- A scheme change is interpreted like a root change. E.g. going from
http://x
to glob://x
acts like a cd
from c:\x
to d:\x
.
- For remote streams (like
http
) and vfs streams, the arguments passed to resolve()
are joined (instead of resolved to an absolute path) with forward slashes (regardless of OS).
Some examples (for Windows, so you can see the difference between local and remote streams), assuming "C:\project" is the current working directory:, (*8)
Additional methods
-
isInside($path, $parent)
- similar to sindresorhus/is-path-inside for node
-
getPrefix($path)
- returns "zip://" for "zip://2015.zip#april/02.log"
install
With composer do:, (*9)
composer require weevers/path
license
MIT © Vincent Weevers and iojs/node authors., (*10)