Skip to content

Commit e0d986d

Browse files
committed
refactor: use property to define adapter class
1 parent f348cc6 commit e0d986d

10 files changed

+41
-17
lines changed

src/Tempest/Storage/src/Config/AzureStorageConfig.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
namespace Tempest\Storage\Config;
44

55
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
6+
use League\Flysystem\FilesystemAdapter;
67
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
78

89
final class AzureStorageConfig implements StorageConfig
910
{
11+
public string $adapter = AzureBlobStorageAdapter::class;
12+
1013
public function __construct(
1114
/**
1215
* Connection string to the Azure Blob Storage account.
@@ -29,7 +32,7 @@ public function __construct(
2932
public bool $readonly = false,
3033
) {}
3134

32-
public function createAdapter(): AzureBlobStorageAdapter
35+
public function createAdapter(): FilesystemAdapter
3336
{
3437
return new AzureBlobStorageAdapter(
3538
client: BlobRestProxy::createBlobService($this->dsn),

src/Tempest/Storage/src/Config/FTPStorageConfig.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace Tempest\Storage\Config;
44

5+
use League\Flysystem\FilesystemAdapter;
56
use League\Flysystem\Ftp\FtpAdapter;
67
use League\Flysystem\Ftp\FtpConnectionOptions;
78

89
final class FTPStorageConfig implements StorageConfig
910
{
11+
public string $adapter = FtpAdapter::class;
12+
1013
public const string WINDOWS = 'windows';
1114

1215
public const string UNIX = 'UNIX';
@@ -29,7 +32,7 @@ public function __construct(
2932
public bool $readonly = false,
3033
) {}
3134

32-
public function createAdapter(): FtpAdapter
35+
public function createAdapter(): FilesystemAdapter
3336
{
3437
return new FtpAdapter(
3538
connectionOptions: FtpConnectionOptions::fromArray([

src/Tempest/Storage/src/Config/GoogleCloudStorageConfig.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace Tempest\Storage\Config;
44

55
use Google\Cloud\Storage\StorageClient;
6-
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
6+
use League\Flysystem\FilesystemAdapter;
77
use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter;
8-
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
98

109
final class GoogleCloudStorageConfig implements StorageConfig
1110
{
11+
public string $adapter = GoogleCloudStorageAdapter::class;
12+
1213
public function __construct(
1314
/**
1415
* Name of the bucket to use.
@@ -46,7 +47,7 @@ public function __construct(
4647
public bool $readonly = false,
4748
) {}
4849

49-
public function createAdapter(): GoogleCloudStorageAdapter
50+
public function createAdapter(): FilesystemAdapter
5051
{
5152
$client = new StorageClient($this->buildClientConfig());
5253

src/Tempest/Storage/src/Config/InMemoryStorageConfig.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
namespace Tempest\Storage\Config;
44

5+
use League\Flysystem\FilesystemAdapter;
56
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
67

78
final class InMemoryStorageConfig implements StorageConfig
89
{
10+
public string $adapter = InMemoryFilesystemAdapter::class;
11+
912
public function __construct(
1013
/**
1114
* Whether the storage is read-only.
1215
*/
1316
public bool $readonly = false,
1417
) {}
1518

16-
public function createAdapter(): InMemoryFilesystemAdapter
19+
public function createAdapter(): FilesystemAdapter
1720
{
1821
return new InMemoryFilesystemAdapter();
1922
}

src/Tempest/Storage/src/Config/LocalStorageConfig.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
final class LocalStorageConfig implements StorageConfig
99
{
10+
public string $adapter = LocalFilesystemAdapter::class;
11+
1012
public function __construct(
1113
/**
1214
* Absolute path to the storage directory.
@@ -19,7 +21,7 @@ public function __construct(
1921
public bool $readonly = false,
2022
) {}
2123

22-
public function createAdapter(): LocalFilesystemAdapter
24+
public function createAdapter(): FilesystemAdapter
2325
{
2426
return new LocalFilesystemAdapter(
2527
location: $this->path,

src/Tempest/Storage/src/Config/S3StorageConfig.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
use Aws\S3\S3Client;
66
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
7+
use League\Flysystem\FilesystemAdapter;
78

89
final class S3StorageConfig implements StorageConfig
910
{
11+
public string $adapter = AwsS3V3Adapter::class;
12+
1013
public function __construct(
1114
/**
1215
* Name of the bucket.
@@ -57,14 +60,15 @@ public function __construct(
5760
* Other options.
5861
*/
5962
public array $options = [],
60-
) {}
63+
) {
64+
}
6165

62-
public function createAdapter(): AwsS3V3Adapter
66+
public function createAdapter(): FilesystemAdapter
6367
{
6468
return new AwsS3V3Adapter(
6569
client: new S3Client($this->buildClientConfig()),
6670
bucket: $this->bucket,
67-
prefix: $this->prefix,
71+
prefix: $this->prefix ?? '',
6872
);
6973
}
7074

src/Tempest/Storage/src/Config/SFTPStorageConfig.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace Tempest\Storage\Config;
44

5+
use League\Flysystem\FilesystemAdapter;
56
use League\Flysystem\PhpseclibV3\SftpAdapter;
67
use League\Flysystem\PhpseclibV3\SftpConnectionProvider;
78

89
final class SFTPStorageConfig implements StorageConfig
910
{
11+
public string $adapter = SftpAdapter::class;
12+
1013
public function __construct(
1114
public string $host,
1215
public string $root,
@@ -22,7 +25,7 @@ public function __construct(
2225
public bool $readonly = false,
2326
) {}
2427

25-
public function createAdapter(): SftpAdapter
28+
public function createAdapter(): FilesystemAdapter
2629
{
2730
return new SftpAdapter(
2831
connectionProvider: new SftpConnectionProvider(

src/Tempest/Storage/src/Config/StorageConfig.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ interface StorageConfig
1414
set;
1515
}
1616

17+
/**
18+
* The adapter class.
19+
*/
20+
public string $adapter {
21+
get;
22+
}
23+
1724
/**
1825
* Creates the adapter.
1926
*/

src/Tempest/Storage/src/Config/ZipArchiveStorageConfig.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
final class ZipArchiveStorageConfig implements StorageConfig
1111
{
12+
public string $adapter = ZipArchiveAdapter::class;
13+
1214
public function __construct(
1315
/**
1416
* Absolute path to the zip file.
@@ -26,7 +28,7 @@ public function __construct(
2628
public bool $readonly = false,
2729
) {}
2830

29-
public function createAdapter(): ZipArchiveAdapter
31+
public function createAdapter(): FilesystemAdapter
3032
{
3133
return new ZipArchiveAdapter(
3234
zipArchiveProvider: new FilesystemZipArchiveProvider($this->path),

src/Tempest/Storage/src/GenericStorage.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use League\Flysystem\FilesystemAdapter;
88
use League\Flysystem\ReadOnly\ReadOnlyFilesystemAdapter;
99
use League\Flysystem\UrlGeneration\TemporaryUrlGenerator;
10-
use ReflectionMethod;
11-
use Tempest\Reflection\MethodReflector;
1210
use Tempest\Storage\Config\StorageConfig;
1311

1412
final class GenericStorage implements Storage
@@ -155,9 +153,7 @@ public function list(string $location = '', bool $deep = false): DirectoryListin
155153

156154
private function createAdapter(): FilesystemAdapter
157155
{
158-
$this->assertAdapterInstalled(
159-
new ReflectionMethod($this->storageConfig, 'createAdapter')->getReturnType()->getName(), // @phpstan-ignore method.notFound
160-
);
156+
$this->assertAdapterInstalled($this->storageConfig->adapter);
161157

162158
$adapter = $this->storageConfig->createAdapter();
163159

0 commit comments

Comments
 (0)