bengor-file/gaufrette-filesystem-bridge
Bridge adapter that makes BenGorFile File objects work with a Gaufrette filesystem. Install via Composer, PHP 5.5+. Includes PHPSpec test suite and links to full documentation in the BenGorFile/File docs.
Installation
composer require bengor-file/gaufrette-filesystem-bridge
Add to config/filesystems.php under disks:
'gaufrette' => [
'driver' => 'gaufrette',
'adapter' => \BenGorFile\GaufretteFilesystemBridge\GaufretteAdapter::class,
'options' => [
'filesystem' => new \Gaufrette\Filesystem(new \Gaufrette\Adapter\Local('/path/to/storage')),
],
],
First Use Case Replace Laravel’s default filesystem with Gaufrette for a specific disk:
use Illuminate\Support\Facades\Storage;
Storage::disk('gaufrette')->put('file.txt', 'Hello Gaufrette!');
$contents = Storage::disk('gaufrette')->get('file.txt');
Key Files to Review
config/filesystems.php (configuration)GaufretteAdapter.php (core adapter logic)GaufretteFilesystem.php (Laravel filesystem wrapper)Hybrid Storage Use Gaufrette for cloud/remote storage (e.g., S3, FTP) while keeping local files on Laravel’s default disk:
// Upload to Gaufrette-backed S3
Storage::disk('gaufrette_s3')->put('remote/file.jpg', file_get_contents('local.jpg'));
// Fallback to local for static assets
Storage::disk('local')->put('static/file.jpg', file_get_contents('local.jpg'));
Dynamic Disk Binding Bind Gaufrette adapters dynamically based on environment:
$adapter = new \Gaufrette\Adapter\Ftp('ftp.example.com', ['username' => 'user', 'password' => 'pass']);
Storage::extend('ftp', function () use ($adapter) {
return new \BenGorFile\GaufretteFilesystemBridge\GaufretteFilesystem(new \Gaufrette\Filesystem($adapter));
});
Streaming Large Files Leverage Gaufrette’s streaming capabilities for memory efficiency:
$stream = Storage::disk('gaufrette')->readStream('large-video.mp4');
// Process stream without loading entire file into memory
Laravel Filesystem Events
Gaufrette’s events (e.g., Gaufrette\Event\File\CreateEvent) can be hooked via Laravel’s Storage::dispatcher():
Storage::disk('gaufrette')->dispatcher()->listen('file.created', function ($event) {
Log::info("File created: {$event->getFile()->getKey()}");
});
Custom Metadata Use Gaufrette’s metadata system to store additional file attributes:
$filesystem = Storage::disk('gaufrette')->getFilesystem();
$metadata = $filesystem->getMetadata('file.txt');
$metadata->setCustomMetadata(['user_id' => 123]);
$filesystem->setMetadata('file.txt', $metadata);
URL Generation Generate URLs via Gaufrette’s URI resolver (if supported by the underlying adapter):
$uri = Storage::disk('gaufrette')->url('file.txt');
How can I help you explore Laravel packages today?