Crell/Path is a simple library that provides typed value objects for handling paths. Paths may be either a PathFragment (no leading /) or an AbsolutePath. An AbsolutePath always begins either with a / or a stream identifier.
The contents of an absolute path may also be retrieved, if there is an actual file that it points to.
A Path object's primary purpose is to centralize and abstract away the various and sundry complexities and edge cases of manipulating paths: Getting a parent path (have to handle the case where there isn't one, with or without a stream), Concatenating two paths (have to handle the leading/trailing slashes, accounting for when one path or the other is the root path), filtering out and rejecting suspicious paths that contain .., and so on.
use Crell\Path\Path;
// Creates a Path Fragment
$frag = Path::create('foo/bar');
// Creates an Absolute Path
$abs = Path::create('/baz/beep');
$new = $abs->concat($frag);
// Prints /baz/beep/foo/bar
print $new;
// Prints /baz/beep/foo
print $new->parent();
$file = '/narf.jpg';
$fileAbs = $abs->concat($file);
// Prints /baz/beep/narf.jpg
print $fileAbs;Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.
The Lesser GPL version 3 or later. Please see License File for more information.