2025-12-23 00:00:45 +00:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Phred\Providers\Core;
|
|
|
|
|
|
|
|
|
|
use DI\Container;
|
|
|
|
|
use DI\ContainerBuilder;
|
|
|
|
|
use League\Flysystem\Filesystem;
|
2025-12-23 00:12:38 +00:00
|
|
|
use League\Flysystem\FilesystemOperator;
|
2025-12-23 00:00:45 +00:00
|
|
|
use League\Flysystem\Local\LocalFilesystemAdapter;
|
|
|
|
|
use Phred\Support\Contracts\ConfigInterface;
|
|
|
|
|
use Phred\Support\Contracts\ServiceProviderInterface;
|
|
|
|
|
|
|
|
|
|
final class StorageServiceProvider implements ServiceProviderInterface
|
|
|
|
|
{
|
|
|
|
|
public function register(ContainerBuilder $builder, ConfigInterface $config): void
|
|
|
|
|
{
|
|
|
|
|
$builder->addDefinitions([
|
2025-12-23 00:12:38 +00:00
|
|
|
FilesystemOperator::class => \DI\get(Filesystem::class),
|
|
|
|
|
Filesystem::class => function (ConfigInterface $config) {
|
|
|
|
|
$default = $config->get('storage.default', 'local');
|
|
|
|
|
$diskConfig = $config->get("storage.disks.$default");
|
2025-12-23 00:00:45 +00:00
|
|
|
|
2025-12-23 00:12:38 +00:00
|
|
|
if (!$diskConfig) {
|
|
|
|
|
throw new \RuntimeException("Storage disk [$default] is not configured.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$driver = $diskConfig['driver'] ?? 'local';
|
|
|
|
|
|
|
|
|
|
if ($driver !== 'local') {
|
|
|
|
|
throw new \RuntimeException("Unsupported storage driver [$driver]. Only 'local' is supported currently.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$root = $diskConfig['root'];
|
2025-12-23 00:00:45 +00:00
|
|
|
$adapter = new LocalFilesystemAdapter($root);
|
2025-12-23 00:12:38 +00:00
|
|
|
|
2025-12-23 00:00:45 +00:00
|
|
|
return new Filesystem($adapter);
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(Container $container): void {}
|
|
|
|
|
}
|