|
3 | 3 | namespace Tempest\Storage; |
4 | 4 |
|
5 | 5 | use Exception; |
| 6 | +use League\Flysystem\AwsS3V3\AwsS3V3Adapter; |
| 7 | +use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter; |
| 8 | +use League\Flysystem\Ftp\FtpAdapter; |
| 9 | +use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter; |
| 10 | +use League\Flysystem\InMemory\InMemoryFilesystemAdapter; |
| 11 | +use League\Flysystem\PhpseclibV3\SftpAdapter; |
| 12 | +use League\Flysystem\ReadOnly\ReadOnlyFilesystemAdapter; |
| 13 | +use League\Flysystem\ZipArchive\ZipArchiveAdapter; |
6 | 14 |
|
7 | 15 | final class MissingAdapterException extends Exception implements StorageException |
8 | 16 | { |
9 | | - public function __construct(string $missing) |
| 17 | + public function __construct( |
| 18 | + private readonly string $missing, |
| 19 | + ) { |
| 20 | + $packageName = $this->getPackageName(); |
| 21 | + $message = $packageName |
| 22 | + ? sprintf('The `%s` adapter is missing. Install it using `composer require %s`.', $missing, $packageName) |
| 23 | + : sprintf('The `%s` adapter is missing.', $missing); |
| 24 | + |
| 25 | + parent::__construct($message); |
| 26 | + } |
| 27 | + |
| 28 | + private function getPackageName(): ?string |
10 | 29 | { |
11 | | - parent::__construct( |
12 | | - message: sprintf('The `%s` adapter is missing.', $missing), |
13 | | - ); |
| 30 | + return match ($this->missing) { |
| 31 | + AwsS3V3Adapter::class => 'league/flysystem-aws-s3-v3', |
| 32 | + InMemoryFilesystemAdapter::class => 'league/flysystem-memory', |
| 33 | + ReadOnlyFilesystemAdapter::class => 'league/flysystem-read-only', |
| 34 | + SftpAdapter::class => 'league/flysystem-sftp', |
| 35 | + ZipArchiveAdapter::class => 'league/flysystem-ziparchive', |
| 36 | + AzureBlobStorageAdapter::class => 'league/flysystem-azure-blob-storage', |
| 37 | + FtpAdapter::class => 'league/flysystem-ftp', |
| 38 | + GoogleCloudStorageAdapter::class => 'league/flysystem-google-cloud-storage', |
| 39 | + default => null, |
| 40 | + }; |
14 | 41 | } |
15 | 42 | } |
0 commit comments