durimjusaj/gaufrette
Filesystem abstraction layer for PHP via Gaufrette. Develop against a unified API and swap storage backends (local, S3, etc.) without changing application code. Includes maintained adapter metapackages with required dependencies and docs.
Gaufrette’s filesystem abstraction layer is a strong fit for Laravel applications requiring multi-cloud storage flexibility, decoupled storage backends, or hybrid storage strategies. Key alignment points:
FilesystemInterface mirrors Laravel’s Filesystem contract, enabling seamless integration with existing Laravel storage logic (e.g., Storage::disk()).KnpGaufretteBundle provides Symfony-style configuration, which Laravel can adopt via config/ or custom service providers.file_get_contents() use cases.Anti-Patterns to Avoid:
| Component | Feasibility | Notes |
|---|---|---|
| Laravel Storage Facade | High | Replace or extend Storage::disk() with Gaufrette’s Filesystem. |
| Symfony Bundle | Medium | KnpGaufretteBundle requires Symfony DI, but Laravel can adapt via config/ or SP. |
| Adapter Installation | High | Use metapackages (e.g., gaufrette/aws-s3-adapter) to avoid SDK conflicts. |
| StreamWrapper | High | Enables gaufrette:// URLs for file_get_contents(), fopen(), etc. |
| Laravel Vapor/Forge | High | Works with AWS S3, Azure Blob, or Google Cloud deployments. |
| Queue Integration | Medium | Async file ops (e.g., processing uploads) require custom queue jobs. |
Critical Integration Points:
// app/Providers/GaufretteServiceProvider.php
public function register()
{
$this->app->singleton('gaufrette.filesystem', function ($app) {
$adapter = new \Gaufrette\Adapter\AwsS3($app['aws']->client('s3'));
return new \Gaufrette\Filesystem($adapter);
});
}
// config/filesystems.php
'disks' => [
's3' => [
'driver' => 'gaufrette',
'adapter' => 'aws_s3',
// Adapter-specific config...
],
'local' => [
'driver' => 'gaufrette',
'adapter' => 'local',
'path' => storage_path('app'),
],
],
// bootstrap/app.php
\Gaufrette\StreamWrapper\StreamWrapper::register();
Now fopen('gaufrette://bucket/file.txt', 'r') works.| Risk | Severity | Mitigation |
|---|---|---|
| Pre-Stable Version | Medium | Monitor for v1.0.0; test thoroughly before production. |
| Adapter Dependency Conflicts | High | Use metapackages (e.g., gaufrette/aws-s3-adapter) to enforce SDK versions. |
| Performance Overhead | Low | Benchmark local vs. cloud adapters (e.g., S3 latency vs. local disk). |
| StreamWrapper Security | High | Validate gaufrette:// URLs to prevent path traversal or SSRF. |
| Symfony Bundle Compatibility | Medium | Abstract Symfony-specific code behind Laravel’s service container. |
| BC Breaks | Medium | Track changelog for deprecated methods (e.g., AwsS3::getUrl()). |
| Async Operations | Medium | Use Laravel Queues for large file processing (e.g., video encoding). |
Key Questions:
Gaufrette integrates cleanly with Laravel’s existing stack:
Storage facade.KnpGaufretteBundle can be adapted for Laravel via config/` or service providers.aws-sdk-php, azure/storage-blob-php).dispatch(new ProcessUpload($file))).Stack Compatibility Matrix:
| Laravel Component | Gaufrette Integration | Notes |
|---|---|---|
| Storage Facade | High | Replace Storage::disk() with Gaufrette’s Filesystem. |
| Symfony Bundle | Medium | Requires adaptation (e.g., custom SP or config). |
| AWS S3 | High | Uses aws-sdk-php v2/v3; supports IAM policies. |
| Azure Blob Storage | High | Supports multi-container mode; requires azure/storage-blob-php. |
| Google Cloud Storage | High | Uses google/cloud-storage. |
| FTP/SFTP | Medium | Requires phpseclib or ssh2 extension. |
| Local Filesystem | High | Zero dependencies; ideal for dev/staging. |
| Queues | Medium | Async ops require custom queue jobs (e.g., HandleFileUpload). |
| StreamWrapper | High | Enables gaufrette:// URLs for file_get_contents(), fopen(), etc. |
composer require knplabs/gaufrette gaufrette/aws-s3-adapter
Storage::disk() in critical paths (e.g., uploads, media library).fopen('gaufrette://bucket/file.jpg', 'r')).config/filesystems.php.Storage calls with Gaufrette.| Component | Compatibility Notes |
|---|---|
| Laravel 10/11 | Full compatibility; uses PHP 8.1+. |
| PHP 8.1+ | Required for newer adapters (e.g., AsyncAws). |
| Symfony 6.x | KnpGaufretteBundle works with Symfony 6; Laravel can adapt via config/SP. |
| AWS SDK v3 | Preferred for S3 adapter (v2 is deprecated). |
| Azure SDK | Requires azure/storage-blob-php (v12+). |
| Google Cloud SDK | Requires `google/cloud |
How can I help you explore Laravel packages today?