PHP code example of jbzoo / path

1. Go to this page and download the library: Download jbzoo/path library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jbzoo / path example snippets




use JBZoo\Path\Path;

// Create path instance
$path = new Path();

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

// Add path aliases
$path
    ->add(__DIR__ . '/assets/css', 'css')
    ->add(__DIR__ . '/assets/js', 'js')
    ->add([
        __DIR__ . '/themes/default/css',
        __DIR__ . '/themes/custom/css'
    ], 'theme-css');

// Find files using aliases
echo $path->get('css:main.css');        // Returns: /project/assets/css/main.css
echo $path->get('js:app.js');           // Returns: /project/assets/js/app.js

// Generate URLs (if root is web accessible)
echo $path->url('css:main.css');        // Returns: https://example.com/assets/css/main.css

// Clean and normalize paths
echo Path::clean('path\\to//file.txt'); // Returns: 'path/to/file.txt'

// Add virtual paths (extending existing aliases)
$path->add('css:vendor/bootstrap');
$path->add('css:vendor/fontawesome');

// Get all registered paths for an alias
$cssPaths = $path->getPaths('css:');
// Returns array of all CSS directories

// Check if file exists in any registered path
if ($path->get('css:custom.css')) {
    echo '<link rel="stylesheet" href="' . $path->url('css:custom.css') . '">';
}

// Multiple file types under one alias
$path->add([
    __DIR__ . '/public/images',
    __DIR__ . '/uploads/images',
    __DIR__ . '/cache/optimized'
], 'images');

// Will search in all image directories
$logoPath = $path->get('images:logo.png');

src/
├── Path.php       # Main Path class
└── Exception.php  # Custom exception class

tests/
├── PathTest.php              # Main test suite
├── PathPhpStormProxyTest.php # IDE integration tests
├── PathPackageTest.php       # Package validation tests
└── phpbench/                 # Performance benchmarks