crell / path
Data model value objects for handling paths.
Fund package maintenance!
Crell
Requires
- php: ~8.4
Requires (Dev)
- phpbench/phpbench: ^1.4.1
- phpstan/phpstan: ^2.1.11
- phpunit/phpunit: ^12.1.0
This package is auto-updated.
Last update: 2025-05-05 05:03:17 UTC
README
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;
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.
Credits
License
The Lesser GPL version 3 or later. Please see License File for more information.