bhittani / filesystem
Utilities for working with the filesystem.
Requires
- php: >=5.6
- symfony/filesystem: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- phpunit/phpunit: <8
This package is auto-updated.
Last update: 2024-12-14 16:14:59 UTC
README
Utilities for working with the filesystem in PHP.
Install
You may install this package using composer.
$ composer require bhittani/filesystem --prefer-dist
Usage
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.
Each
Traverse over all the files (recursive) in a directory.
$fs->each('/path/to/a/directory', function (\SplFileInfo $splFileInfo) { // Do something... });
Inject
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
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 Contents
Get the contents of a file with an optional payload.
$fs->getContents('/path/to/file', [ 'foo' => 'bar', ]);
Static Access
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.
Changelog
Please see CHANGELOG for more information on what has changed.
Testing
git clone https://github.com/kamalkhan/filesystem cd filesystem composer install composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email shout@bhittani.com
instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see the License File for more information.