PHP code example of herrera-io / file-locator

1. Go to this page and download the library: Download herrera-io/file-locator 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/ */

    

herrera-io / file-locator example snippets




use Herrera\FileLocator\Locator\FileSystemLocator;

$locator = new FileSystemLocator('/path/to/dir');
$locator = new FileSystemLocator(array(
    '/path/to/dir1',
    '/path/to/dir2',
    '/path/to/dir3' // etc
));

$file = $locator->locate('file.ini'); // return the first "file.ini" found
$files = $locator->locate('file.ini', false); // find all named "file.ini"



use Herrera\FileLocator\Locator\LocatorInterface;

class MyLocator implements LocatorInterface
{
    public function locate($file, $first = true)
    {
        // do something to locate $file

        // if $first is true, return the first matching result
            // if nothing is found, return null

        // if $first is false, generate a list of found $file(s) and return it
            // if nothing is found, return an empty array
    }
}



use Herrera\FileLocator\Collection;
use Herrera\FileLocator\Locator\FileSystemLocator;
use My\Library\CustomLocator;

$locators = new Collection();
$locators->add(new FileSystemLocator('/path/to/dir'));
$locators->add(new CustomLocator());

$file = $locator->locate('file.ini'); // return the first "file.ini" found
$files = $locator->locate('file.ini', false); // find all named "file.ini"