halimonalexander/filesystem

Filesystem fetcher library

v1.0 2020-12-03 04:49 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:19 UTC


README

Filesystem fetcher library that can help with fetching files, directories or both of them from a provided path.

Additional filters can be applied to the response to get more sensetive results.

Usage:

use HalimonAlexander\Filesystem\Filesystem;
use HalimonAlexander\Filesystem\Filters\ExtensionFilter;

$filesystem = new Filesystem();
$files = $filesystem
    ->enter('/var/log/mysql/')
    ->files()
    ->filter(new ExtensionFilter('log'))
    ->get();

$folders = $filesystem
    ->enter('/var/www/app/')
    ->directories()
    ->get();

$foldersWithFiles = $filesystem
    ->enter('/etc/nginx/')
    ->get();

Filters:

ExtensionFilter

Can be applied for files only to filter by provided file extension. In other cases will throw an error.

use HalimonAlexander\Filesystem\Filesystem;
use HalimonAlexander\Filesystem\Filters\ExtensionFilter;

$filesystem = new Filesystem();
$files = $filesystem
    ->enter('/var/log/mysql/')
    ->files()
    ->filter(new ExtensionFilter('log'))
    ->get();

RegexpFilter

Can be applied to any type of result.

use HalimonAlexander\Filesystem\Filesystem;
use HalimonAlexander\Filesystem\Filters\RegexpFilter;

$filesystem = new Filesystem();
$files = $filesystem
    ->enter('/var/log/mysql/')
    ->filter(new RegexpFilter('2020-01-01(.*)'))
    ->get();

Combining filters

Filters can be combined to receive the best results.

use HalimonAlexander\Filesystem\Filesystem;
use HalimonAlexander\Filesystem\Filters\ExtensionFilter;
use HalimonAlexander\Filesystem\Filters\RegexpFilter;

$filesystem = new Filesystem();
$files = $filesystem
    ->enter('/var/log/mysql/')
    ->files()
    ->filter(new ExtensionFilter('log'))
    ->filter(new RegexpFilter('2020-01-\d{2}.*'))
    ->filter(new RegexpFilter('\d{4}-\d{2}-d{2}_1.*'))
    ->get();