## Getting Started
This package (`php-translation/symfony-storage`) provides Laravel-friendly abstractions for Symfony's storage components (e.g., `StorageInterface`, `Filesystem`, `AdapterInterface`). **Updated for PHP 8.2+ and Symfony 7.x** in v2.4.0.
### **Installation**
```bash
composer require php-translation/symfony-storage
Requirements: PHP 8.2–8.3 (dropped support for PHP 7.x–8.0 in v2.4.0).
config/app.php:
'providers' => [
PhpTranslation\SymfonyStorage\SymfonyStorageServiceProvider::class,
],
AppServiceProvider):
$this->app->bind(\Symfony\Component\Filesystem\Filesystem::class, function () {
return new \Symfony\Component\Filesystem\Filesystem();
});
Use Symfony’s Filesystem for file operations:
use Symfony\Component\Filesystem\Filesystem;
$filesystem = app(Filesystem::class);
$filesystem->dumpFile('/path/to/file.txt', 'content');
Resolve Symfony components via Laravel’s container:
// Symfony Filesystem
$filesystem = app(\Symfony\Component\Filesystem\Filesystem::class);
// Flysystem Adapter (if bound)
$adapter = app(\League\Flysystem\AdapterInterface::class);
Extend Laravel’s FilesystemManager to use Symfony adapters:
$this->app->extend('filesystem', function ($filesystem) {
$symfonyAdapter = app(\League\Flysystem\AdapterInterface::class);
return $filesystem->addAdapter('symfony', $symfonyAdapter);
});
Leverage Symfony’s UploadedFile for HTTP uploads:
use Symfony\Component\HttpFoundation\File\UploadedFile;
public function upload(UploadedFile $file) {
$file->move($this->getTargetPath(), $file->getClientOriginalName());
}
No additional config is required. For custom adapters, bind them explicitly:
$this->app->bind(\Symfony\Component\Filesystem\Filesystem::class, function () {
return new \Symfony\Component\Filesystem\Filesystem(new \Symfony\Component\Filesystem\LocalFilesystemAdapter('/custom/path'));
});
League\Flysystem\AdapterInterface or Symfony\Component\Filesystem\Filesystem.Filesystem uses absolute paths. Use realpath() or symfony/finder for relative paths.Symfony\Component\Filesystem\Adapter\AbstractAdapter for bespoke storage.FilesystemEvent for pre/post-file operations.Symfony\Component\HttpFoundation\StreamedResponse for large files to avoid memory overload.Filesystem::mkdir() with 0775).PathUtil) may require updates to existing logic.PathUtil::canonicalize()).StreamedFile for efficient large-file handling.
NO_UPDATE_NEEDED would **not** apply here due to the breaking changes (PHP version drop, Symfony 7.x support) and new usage patterns. The assessment has been updated to reflect these changes.
How can I help you explore Laravel packages today?