From 9650ef35b0c41975115d5b9bc42866827f1c97bc Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 27 Dec 2023 17:22:08 +0100 Subject: [PATCH 1/2] Init league/flysystem-v3 --- composer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 264920b..408c02c 100644 --- a/composer.json +++ b/composer.json @@ -19,14 +19,13 @@ "ext-fileinfo": "*", "ext-json": "*", "ext-mbstring": "*", - "php-collective/file-storage-factories": "dev-master as 1.0", + "php-collective/file-storage-factories": "dev-league/flysystem-v3 as 1.0", "psr/http-message": "^1.0|^2.0" }, "require-dev": { "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^10.3", - "php-collective/code-sniffer": "^0.2.1", - "php-collective/file-storage-image-processor": "dev-master as 1.0" + "php-collective/code-sniffer": "^0.2.1" }, "suggest": { "php-collective/file-storage-image-processor": "For image processing" From 19f9bd8939219b56bd3e80422832ca85040a56bc Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 27 Dec 2023 17:29:00 +0100 Subject: [PATCH 2/2] Init league/flysystem-v3 --- src/AdapterCollection.php | 10 +++--- src/AdapterCollectionInterface.php | 10 +++--- src/FileStorage.php | 6 ++-- src/FileStorageInterface.php | 6 ++-- src/StorageService.php | 50 +++++++----------------------- src/StorageServiceInterface.php | 18 +++++------ 6 files changed, 37 insertions(+), 63 deletions(-) diff --git a/src/AdapterCollection.php b/src/AdapterCollection.php index a6000fc..c5fad93 100644 --- a/src/AdapterCollection.php +++ b/src/AdapterCollection.php @@ -15,7 +15,7 @@ use ArrayIterator; use Iterator; -use League\Flysystem\AdapterInterface; +use League\Flysystem\FilesystemAdapter; use RuntimeException; /** @@ -38,13 +38,13 @@ public function __construct() /** * @param string $name Name - * @param \League\Flysystem\AdapterInterface $adapter Adapter + * @param \League\Flysystem\FilesystemAdapter $adapter Adapter * * @throws \RuntimeException * * @return void */ - public function add($name, AdapterInterface $adapter) + public function add($name, FilesystemAdapter $adapter) { if ($this->has($name)) { throw new RuntimeException(sprintf( @@ -81,9 +81,9 @@ public function has(string $name): bool * * @throws \RuntimeException * - * @return \League\Flysystem\AdapterInterface + * @return \League\Flysystem\FilesystemAdapter */ - public function get(string $name): AdapterInterface + public function get(string $name): FilesystemAdapter { if (!$this->has($name)) { throw new RuntimeException(sprintf( diff --git a/src/AdapterCollectionInterface.php b/src/AdapterCollectionInterface.php index 3a88254..67d8a8b 100644 --- a/src/AdapterCollectionInterface.php +++ b/src/AdapterCollectionInterface.php @@ -14,7 +14,7 @@ namespace PhpCollective\Infrastructure\Storage; use IteratorAggregate; -use League\Flysystem\AdapterInterface; +use League\Flysystem\FilesystemAdapter; /** * Factory Collection Interface @@ -23,11 +23,11 @@ interface AdapterCollectionInterface extends IteratorAggregate { /** * @param string $name Name - * @param \League\Flysystem\AdapterInterface $adapter Adapter + * @param \League\Flysystem\FilesystemAdapter $adapter Adapter * * @return void */ - public function add($name, AdapterInterface $adapter); + public function add($name, FilesystemAdapter $adapter); /** * @param string $name Name @@ -46,9 +46,9 @@ public function has(string $name): bool; /** * @param string $name * - * @return \League\Flysystem\AdapterInterface + * @return \League\Flysystem\FilesystemAdapter */ - public function get(string $name): AdapterInterface; + public function get(string $name): FilesystemAdapter; /** * Empties the collection diff --git a/src/FileStorage.php b/src/FileStorage.php index 1eef883..ce4ebe7 100644 --- a/src/FileStorage.php +++ b/src/FileStorage.php @@ -15,8 +15,8 @@ namespace PhpCollective\Infrastructure\Storage; use InvalidArgumentException; -use League\Flysystem\AdapterInterface; use League\Flysystem\Config; +use League\Flysystem\FilesystemAdapter; use PhpCollective\Infrastructure\Storage\PathBuilder\PathBuilderInterface; use PhpCollective\Infrastructure\Storage\Processor\Exception\VariantDoesNotExistException; use PhpCollective\Infrastructure\Storage\Processor\Exception\VariantException; @@ -203,9 +203,9 @@ public function removeVariant(FileInterface $file, string $name): FileInterface * * @param string $storage Storage name to use * - * @return \League\Flysystem\AdapterInterface + * @return \League\Flysystem\FilesystemAdapter */ - public function getStorage(string $storage): AdapterInterface + public function getStorage(string $storage): FilesystemAdapter { return $this->storageService->adapter($storage); } diff --git a/src/FileStorageInterface.php b/src/FileStorageInterface.php index a7de780..5498560 100644 --- a/src/FileStorageInterface.php +++ b/src/FileStorageInterface.php @@ -14,8 +14,8 @@ namespace PhpCollective\Infrastructure\Storage; -use League\Flysystem\AdapterInterface; use League\Flysystem\Config; +use League\Flysystem\FilesystemAdapter; /** * FileStorageInterface @@ -55,7 +55,7 @@ public function removeVariant(FileInterface $file, string $name): FileInterface; * * @param string $storage Storage name to use * - * @return \League\Flysystem\AdapterInterface + * @return \League\Flysystem\FilesystemAdapter */ - public function getStorage(string $storage): AdapterInterface; + public function getStorage(string $storage): FilesystemAdapter; } diff --git a/src/StorageService.php b/src/StorageService.php index 7a31361..14c945e 100644 --- a/src/StorageService.php +++ b/src/StorageService.php @@ -14,9 +14,8 @@ namespace PhpCollective\Infrastructure\Storage; -use League\Flysystem\AdapterInterface; use League\Flysystem\Config; -use PhpCollective\Infrastructure\Storage\Exception\StorageException; +use League\Flysystem\FilesystemAdapter; use PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryNotFoundException; use RuntimeException; @@ -81,7 +80,7 @@ public function adapters(): AdapterCollectionInterface * * @throws \PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryNotFoundException */ - public function adapter(string $name): AdapterInterface + public function adapter(string $name): FilesystemAdapter { if ($this->adapterCollection->has($name)) { return $this->adapterCollection->get($name); @@ -103,9 +102,9 @@ public function adapter(string $name): AdapterInterface * @param string $adapter Adapter * @param array $options * - * @return \League\Flysystem\AdapterInterface + * @return \League\Flysystem\FilesystemAdapter */ - public function loadAdapter(string $name, string $adapter, array $options): AdapterInterface + public function loadAdapter(string $name, string $adapter, array $options): FilesystemAdapter { $adapter = $this->adapterFactory->buildStorageAdapter( $adapter, @@ -174,45 +173,20 @@ protected function makeConfigIfNeeded(?Config $config) /** * @inheritDoc - * - * @throws \PhpCollective\Infrastructure\Storage\Exception\StorageException */ - public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): array + public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): void { $config = $this->makeConfigIfNeeded($config); - $result = $this->adapter($adapter)->writeStream($path, $resource, $config); - - if ($result === false) { - throw new StorageException(sprintf( - 'Failed to store resource stream to in `%s` with path `%s`', - $adapter, - $path, - )); - } - - return $result; + $this->adapter($adapter)->writeStream($path, $resource, $config); } /** * @inheritDoc - * - * @throws \PhpCollective\Infrastructure\Storage\Exception\StorageException */ - public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): array + public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): void { $config = $this->makeConfigIfNeeded($config); - $result = $this->adapter($adapter)->write($path, (string)file_get_contents($file), $config); - - if ($result === false) { - throw new StorageException(sprintf( - 'Failed to store file `%s` in `%s` with path `%s`', - $file, - $adapter, - $path, - )); - } - - return $result; + $this->adapter($adapter)->write($path, (string)file_get_contents($file), $config); } /** @@ -223,17 +197,17 @@ public function storeFile(string $adapter, string $path, string $file, ?Config $ */ public function fileExists(string $adapter, string $path): bool { - return $this->adapter($adapter)->has($path); + return $this->adapter($adapter)->fileExists($path); } /** * @param string $adapter Name * @param string $path File to delete * - * @return bool + * @return void */ - public function removeFile(string $adapter, string $path): bool + public function removeFile(string $adapter, string $path): void { - return $this->adapter($adapter)->delete($path); + $this->adapter($adapter)->delete($path); } } diff --git a/src/StorageServiceInterface.php b/src/StorageServiceInterface.php index 495778a..9b963ab 100644 --- a/src/StorageServiceInterface.php +++ b/src/StorageServiceInterface.php @@ -14,8 +14,8 @@ namespace PhpCollective\Infrastructure\Storage; -use League\Flysystem\AdapterInterface; use League\Flysystem\Config; +use League\Flysystem\FilesystemAdapter; /** * StorageServiceInterface @@ -41,9 +41,9 @@ public function adapters(): AdapterCollectionInterface; * * @param string $name * - * @return \League\Flysystem\AdapterInterface + * @return \League\Flysystem\FilesystemAdapter */ - public function adapter(string $name): AdapterInterface; + public function adapter(string $name): FilesystemAdapter; /** * Adds an adapter config @@ -64,9 +64,9 @@ public function addAdapterConfig(string $name, string $class, array $options); * @param resource $resource Resource to store * @param \League\Flysystem\Config|null $config * - * @return array + * @return void */ - public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): array; + public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): void; /** * Stores a file in a storage backend @@ -76,9 +76,9 @@ public function storeResource(string $adapter, string $path, $resource, ?Config * @param string $file File to store * @param \League\Flysystem\Config|null $config * - * @return array + * @return void */ - public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): array; + public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): void; /** * Checks if a file exists in a store @@ -96,7 +96,7 @@ public function fileExists(string $adapter, string $path): bool; * @param string $adapter Name * @param string $path File to delete * - * @return bool + * @return void */ - public function removeFile(string $adapter, string $path): bool; + public function removeFile(string $adapter, string $path): void; }