PHP virtual path library

3.0.2 2020-07-31 16:59 UTC

This package is auto-updated.

Last update: 2020-07-31 18:04:16 UTC


Build Status Coverage Status Psalm Coverage
Stable Version Latest Unstable Version Dependents GitHub Issues Total Downloads GitHub License

Create memory based aliases for your project file system.


use JBZoo\Path\Path;

//  Get path instance.
$path = new Path();

//  Setup root directory.

//  Add paths.
    ->add(__DIR__ . '/styles/css', 'css')
    ->add(__DIR__ . '/simple/styles/css', 'css')
    //  Add array paths.
        __DIR__ . 'styles/folder/less',
        __DIR__ . 'theme/styles/less',
    ], 'less');

 * Add paths by virtual.
 * If you already added at least one one way, you can use the virtual paths

//  Get added path list by key.

 * Get full path for the first file found, if file exits.
echo $path->get('css:styles.css');           //  result: /jbzoo/styles/css/styles.css
echo $path->get('less:path/to/styles.less'); //  result: /jbzoo/styles/folder/less/path/to/styles.less

 * Get url for the first file found, if file exits.
 * If - "C:/Server/jbzoo" is root dir we have...
$path->url('css:styles.css');               //  http://my-site.com/styles/css/styles.css
$path->url('less:path/to/styles.less');     //  http://my-site.com/styles/css/folder/less/path/to/styles.less

echo '<link rel="stylesheet" href="' . $path->url('css:styles.css') . '">';

//  Clean path.
Path::clean('path\\to//simple\\folder');    //  result: 'path/to/simple/folder'

Summary benchmark info (execution time)

See details here

subject groups its revs mean stdev rstdev mem_real diff
benchBaseline 3 10000 2.53μs 0.11μs 4.39% 6,291,456b 1.00x
benchNative 3 10000 138.22μs 0.46μs 0.33% 6,291,456b 54.64x
benchJBZooPath 3 10000 192.58μs 0.87μs 0.45% 6,291,456b 76.13x

Unit tests and check code style

make update
make test-all