PHP code example of metra / cascading-filesystem

1. Go to this page and download the library: Download metra/cascading-filesystem 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/ */

    

metra / cascading-filesystem example snippets


// Enable composer autoloading

use Kohana\CascadingFilesystem\Filesystem\CascadingFilesystem;
use Doctrine\Common\Cache\ArrayCache;

// Instantiate cache
$cache = new ArrayCache();

// Instantiate CFS
$cfs = new CascadingFilesystem($cache, [
    'directory/path/one',
    'directory/path/two',
    'directory/path/three',
]);

// Get absolute path
$path = $cfs->getPath('code/foo.php');

// Get all absolute paths
$paths = $cfs->getAllPaths('code/foo.php');

// List directory contents
$files = $cfs->listFiles('code');

use Kohana\CascadingFilesystem\Initializer\ModulesInitializer;

// Initialize all modules
(new ModulesInitializer($cfs))->initialize();

use Kohana\CascadingFilesystem\Autoloader\ModulesAutoloader;

// Register Kohana module autoloader
(new ModulesAutoloader($cfs))->register();

use Kohana\CascadingFilesystem\Autoloader\LegacyModulesAutoloader;

// Register legacy Kohana module autoloader
(new LegacyModulesAutoloader($cfs))->register();

directory 1
|-- cat.png
|-- code
|    |-- Foo.php
|    |-- Bar.php
|    +-- Baz.php
+-- music
     +-- White & Nerdy.mp3

directory 2
|-- dog.bmp
|-- mouse.jpg
+-- code
     +-- Foo.php

directory 3
|-- cat.png
+-- code
     |-- Foo.php
     +-- Baz.php

root
|-- cat.png (From directory 3)
|-- dog.bmp (From directory 2)
|-- mouse.jpg (From directory 2)
|-- code
|    |-- Foo.php (From directory 3)
|    |-- Bar.php (From directory 1)
|    +-- Baz.php (From directory 3)
+-- music
     +-- White & Nerdy.mp3 (From directory 1)