Utilities for working with the filesystem in PHP.
You may install this package using composer.
$ composer require bhittani/filesystem --prefer-dist
This packages offers some helpful utilities when working with the filesystem. It extends symfony/filesystem.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$fs = new \Bhittani\Filesystem\Filesystem;
// Use the API calls as demonstrated below.
Traverse over all the files (recursive) in a directory.
$fs->each('/path/to/a/directory', function (\SplFileInfo $splFileInfo) {
// Do something...
});
Inject a payload into a file or every file in a directory.
$fs->inject('/path/to/a/file/or/directory', [
'foo' => 'bar',
]);
This will lazily find
[foo]
in each file contents and replace it withbar
.
A callback is also accepted as the payload which will receive the path to the current file.
Dump a file or directory with an optional payload.
$fs->dump('/path/to/a/dest/directory', '/path/to/a/src/directory', [
'foo' => 'bar',
]);
If a callback is provided as the payload, it will receive the path to the current destination file.
Get the contents of a file with an optional payload.
$fs->getContents('/path/to/file', [
'foo' => 'bar',
]);
A StaticFilesystem
class is available.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Bhittani\Filesystem\StaticFilesystem;
echo StaticFilesystem::getContents('/path/to/file');
Any of the public methods may be invoked by static access.
Please see CHANGELOG for more information on what has changed.
git clone https://github.com/kamalkhan/filesystem
cd filesystem
composer install
composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email shout@bhittani.com
instead of using the issue tracker.
The MIT License (MIT). Please see the License File for more information.