jbzoo/path

PHP virtual path library

7.0.1 2024-01-28 11:05 UTC

This package is auto-updated.

Last update: 2024-10-28 13:01:28 UTC


README

CI Coverage Status Psalm Coverage Psalm Level CodeFactor
Stable Version Total Downloads Dependents GitHub License

Create memory based aliases for your project file system.

Usage

use JBZoo\Path\Path;

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

//  Setup root directory.
$path->setRoot(__DIR__);

//  Add paths.
$path
    ->add(__DIR__ . '/styles/css', 'css')
    ->add(__DIR__ . '/simple/styles/css', 'css')
    //  Add array paths.
    ->add([
        __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
 */
$path->add('less:assets/less');
$path->add('css:assets/less');

//  Get added path list by key.
var_dump($path->getPaths('css:'));
var_dump($path->getPaths('less:'));

/**
 * 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

Unit tests and check code style

make update
make test-all

License

MIT