Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Symfony Storage Laravel Package

php-translation/symfony-storage

View on GitHub
Deep Wiki
Context7
## 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).

Basic Setup

  1. Register the service provider in config/app.php:
    'providers' => [
        PhpTranslation\SymfonyStorage\SymfonyStorageServiceProvider::class,
    ],
    
  2. Bind Symfony components (e.g., in AppServiceProvider):
    $this->app->bind(\Symfony\Component\Filesystem\Filesystem::class, function () {
        return new \Symfony\Component\Filesystem\Filesystem();
    });
    

First Use Case

Use Symfony’s Filesystem for file operations:

use Symfony\Component\Filesystem\Filesystem;

$filesystem = app(Filesystem::class);
$filesystem->dumpFile('/path/to/file.txt', 'content');

Implementation Patterns

Dependency Injection

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);

Laravel Filesystem Integration

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);
});

Upload Handling

Leverage Symfony’s UploadedFile for HTTP uploads:

use Symfony\Component\HttpFoundation\File\UploadedFile;

public function upload(UploadedFile $file) {
    $file->move($this->getTargetPath(), $file->getClientOriginalName());
}

Configuration

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'));
});

Gotchas and Tips

Breaking Changes (v2.4.0)

  • PHP Version: Mandatory upgrade to PHP 8.2–8.3. PHP 7.x–8.0 no longer supported.
  • Symfony 7.x: Now fully supported. Test thoroughly if using Symfony 6.x.
  • Roave BC Check: Dropped (no impact on usage, but third-party tools may need updates).

Debugging

  • Adapter Errors: Verify the bound adapter implements League\Flysystem\AdapterInterface or Symfony\Component\Filesystem\Filesystem.
  • Path Issues: Symfony’s Filesystem uses absolute paths. Use realpath() or symfony/finder for relative paths.

Extension Points

  • Custom Adapters: Extend Symfony\Component\Filesystem\Adapter\AbstractAdapter for bespoke storage.
  • Event Integration: Use Symfony’s FilesystemEvent for pre/post-file operations.

Performance

  • Reuse Instances: Laravel’s container caches Symfony components by default.
  • Streaming: Use Symfony\Component\HttpFoundation\StreamedResponse for large files to avoid memory overload.

Common Pitfalls

  • Permissions: Ensure target directories are writable (use Filesystem::mkdir() with 0775).
  • Case Sensitivity: Symfony’s filesystem is case-sensitive on Linux. Normalize paths for cross-platform use.
  • Symfony 7.x: New features (e.g., PathUtil) may require updates to existing logic.

Symfony 7.x Features

  • PathUtil: Use for path manipulation (e.g., PathUtil::canonicalize()).
  • Streaming Improvements: Leverage 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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver