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

Storage Laravel Package

spiral/storage

Spiral Storage is a PHP component for managing application storage: define locations and storage buckets, resolve filesystem paths consistently, and integrate with Spiral apps. Lightweight, typed, tested, and MIT-licensed.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer: composer require spiral/storage
  2. Choose an adapter (e.g., LocalAdapter, InMemoryAdapter, or third-party like AwsS3Adapter if available)
  3. ** Instantiate storage** with your adapter:
    use Spiral\Storage\LocalAdapter;
    use Spiral\Storage\Storage;
    
    $storage = new Storage(new LocalAdapter('/var/www/storage/app'));
    
  4. First use case: Save an uploaded file
    $storage->write('avatars/user_123.jpg', fopen('/tmp/uploaded.jpg', 'r'));
    

Start with LocalAdapter for local development, then switch to cloud or in-memory for production/testing.

Implementation Patterns

  • Dependency Injection: Inject StorageInterface (from Spiral\Storage traits) into services instead of concrete adapters. Enables easy swapping and mocking.
  • Backend abstraction: Define storage drivers in config:
    // config/storage.php
    return [
        'default' => env('STORAGE_DRIVER', 'local'),
        'drivers' => [
            'local' => LocalAdapter::class,
            's3' => AwsS3Adapter::class,
        ]
    ];
    
  • Test-first workflow: Use InMemoryAdapter for unit tests to avoid real filesystem side effects.
  • Stream handling: Pass resources or Psr\Http\Message\StreamInterface for large file writes to avoid memory bloat.
  • Namespacing via paths: Store tenant- or context-specific files with path prefixes ('uploads/2024/avatars/…') and rely on list($prefix) to scope results.

Gotchas and Tips

  • No async I/O: Fully synchronous — avoid for high-throughput streaming without pooling/queueing.
  • Visibility support inconsistent: Only some adapters (e.g., S3) implement visibility flags (public/private). Local adapter treats all as public. Always check adapter docs.
  • Path normalization: Input paths are normalized but not validated—ensure user-supplied paths sanitize against directory traversal (e.g., resolve basename() or use Path::makeRelative() helpers if available).
  • Missing modern PSR standards: This package predates PSR-18/PSR-7 stream adoption fully; you may need bridges for PSR-7/18 integration (e.g., wrap Psr\Http\Message\StreamInterface with StreamFactory).
  • Stale release: Last update in 2019 — verify adapter compatibility with newer PHP versions (≥7.4) and cloud SDKs (e.g., AWS SDK v3 requires guzzlehttp/guzzle:^6.0).
  • Extend with decorators: Wrap Storage with retry logic or logging adapters:
    $storage = new LoggingStorage(new RedisAdapter($client), $logger);
    
  • Testability: Use InMemoryAdapter in tests and assert content via $storage->read('file.txt').
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.
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
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle