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.
composer require spiral/storageLocalAdapter, InMemoryAdapter, or third-party like AwsS3Adapter if available)use Spiral\Storage\LocalAdapter;
use Spiral\Storage\Storage;
$storage = new Storage(new LocalAdapter('/var/www/storage/app'));
$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.
StorageInterface (from Spiral\Storage traits) into services instead of concrete adapters. Enables easy swapping and mocking.// config/storage.php
return [
'default' => env('STORAGE_DRIVER', 'local'),
'drivers' => [
'local' => LocalAdapter::class,
's3' => AwsS3Adapter::class,
]
];
InMemoryAdapter for unit tests to avoid real filesystem side effects.Psr\Http\Message\StreamInterface for large file writes to avoid memory bloat.'uploads/2024/avatars/…') and rely on list($prefix) to scope results.public/private). Local adapter treats all as public. Always check adapter docs.basename() or use Path::makeRelative() helpers if available).Psr\Http\Message\StreamInterface with StreamFactory).guzzlehttp/guzzle:^6.0).Storage with retry logic or logging adapters:
$storage = new LoggingStorage(new RedisAdapter($client), $logger);
InMemoryAdapter in tests and assert content via $storage->read('file.txt').How can I help you explore Laravel packages today?