dev-master
9999999-dev https://github.com/rubendg/pathtypeUnix path manipulation
The Requires
- php >=5.4
- phpoption/phpoption *
The Development Requires
by Ruben de Gooijer
file filesystem directory unix filepath
Unix path manipulation
An OO library for Unix path manipulation. The properties of a path absolute/relative file or directory are reflected in the type and invalid operations (like appending an absolute directory path to an relative file path) are simply not possible by construction., (*2)
The library is heavily inspired by the Haskell pathtype library, but is not meant to be a port in anyway. Here is the type hierachy:, (*3)
, (*4)
A quick example., (*5)
Using the factory function Path::from
we can produce any of the types in the bottom
of the diagram. It takes a well-formed path string and a flag indicating whether the path
is a directory or a file (since this cannot actually be determined from the path in all cases)., (*6)
$path = '/etc/apache2/site-enabled'; $sitesEnabled = Path::from($path, is_dir($path)); function newApacheConfig(AbsDir $sitesEnabled, $name) { mkdir($sitesEnabled ->append('sites-enabled') ->append($name) ->get()); } newApacheConfig($sitesEnabled);
One of the added benefits besides the path manipulation functions is that we can now use type hinting in order to express that newApacheConfig expects an absolute directory path., (*7)
Notes:, (*8)
Warning: this library is not battle tested, (*9)
Similar:, (*10)
Unix path manipulation
file filesystem directory unix filepath