From 7732b82e8b06175bb057bbe543739c7acb6e66f0 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Mon, 6 Nov 2023 21:49:49 +0100 Subject: [PATCH 1/2] Add abstract DecoratedAdapter base class --- src/DecoratedAdapter.php | 100 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/DecoratedAdapter.php diff --git a/src/DecoratedAdapter.php b/src/DecoratedAdapter.php new file mode 100644 index 000000000..9d8cd13af --- /dev/null +++ b/src/DecoratedAdapter.php @@ -0,0 +1,100 @@ +adapter->fileExists($path); + } + + public function directoryExists(string $path): bool + { + return $this->adapter->directoryExists($path); + } + + public function write(string $path, string $contents, Config $config): void + { + $this->adapter->write($path, $contents, $config); + } + + public function writeStream(string $path, $contents, Config $config): void + { + $this->adapter->writeStream($path, $contents, $config); + } + + public function read(string $path): string + { + return $this->adapter->read($path); + } + + public function readStream(string $path) + { + return $this->adapter->readStream($path); + } + + public function delete(string $path): void + { + $this->adapter->delete($path); + } + + public function deleteDirectory(string $path): void + { + $this->adapter->deleteDirectory($path); + } + + public function createDirectory(string $path, Config $config): void + { + $this->adapter->createDirectory($path, $config); + } + + public function setVisibility(string $path, string $visibility): void + { + $this->adapter->setVisibility($path, $visibility); + } + + public function visibility(string $path): FileAttributes + { + return $this->adapter->visibility($path); + } + + public function mimeType(string $path): FileAttributes + { + return $this->adapter->mimeType($path); + } + + public function lastModified(string $path): FileAttributes + { + return $this->adapter->lastModified($path); + } + + public function fileSize(string $path): FileAttributes + { + return $this->adapter->fileSize($path); + } + + public function listContents(string $path, bool $deep): iterable + { + return $this->adapter->listContents($path, $deep); + } + + public function move(string $source, string $destination, Config $config): void + { + $this->adapter->move($source, $destination, $config); + } + + public function copy(string $source, string $destination, Config $config): void + { + $this->adapter->copy($source, $destination, $config); + } +} From 925db2294ad0ff9599a4602810e0c46821e15f08 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Mon, 6 Nov 2023 21:51:19 +0100 Subject: [PATCH 2/2] Update ReadOnlyFilesystemAdapter to extend DecoratedAdapter --- src/ReadOnly/ReadOnlyFilesystemAdapter.php | 53 +--------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/src/ReadOnly/ReadOnlyFilesystemAdapter.php b/src/ReadOnly/ReadOnlyFilesystemAdapter.php index 3eaf40af4..2a6fc1517 100644 --- a/src/ReadOnly/ReadOnlyFilesystemAdapter.php +++ b/src/ReadOnly/ReadOnlyFilesystemAdapter.php @@ -6,7 +6,7 @@ use League\Flysystem\CalculateChecksumFromStream; use League\Flysystem\ChecksumProvider; use League\Flysystem\Config; -use League\Flysystem\FileAttributes; +use League\Flysystem\DecoratedAdapter; use League\Flysystem\FilesystemAdapter; use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToCreateDirectory; @@ -20,24 +20,10 @@ use League\Flysystem\UrlGeneration\PublicUrlGenerator; use League\Flysystem\UrlGeneration\TemporaryUrlGenerator; -class ReadOnlyFilesystemAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider, TemporaryUrlGenerator +class ReadOnlyFilesystemAdapter extends DecoratedAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider, TemporaryUrlGenerator { use CalculateChecksumFromStream; - public function __construct(private FilesystemAdapter $adapter) - { - } - - public function fileExists(string $path): bool - { - return $this->adapter->fileExists($path); - } - - public function directoryExists(string $path): bool - { - return $this->adapter->directoryExists($path); - } - public function write(string $path, string $contents, Config $config): void { throw UnableToWriteFile::atLocation($path, 'This is a readonly adapter.'); @@ -48,16 +34,6 @@ public function writeStream(string $path, $contents, Config $config): void throw UnableToWriteFile::atLocation($path, 'This is a readonly adapter.'); } - public function read(string $path): string - { - return $this->adapter->read($path); - } - - public function readStream(string $path) - { - return $this->adapter->readStream($path); - } - public function delete(string $path): void { throw UnableToDeleteFile::atLocation($path, 'This is a readonly adapter.'); @@ -78,31 +54,6 @@ public function setVisibility(string $path, string $visibility): void throw UnableToSetVisibility::atLocation($path, 'This is a readonly adapter.'); } - public function visibility(string $path): FileAttributes - { - return $this->adapter->visibility($path); - } - - public function mimeType(string $path): FileAttributes - { - return $this->adapter->mimeType($path); - } - - public function lastModified(string $path): FileAttributes - { - return $this->adapter->lastModified($path); - } - - public function fileSize(string $path): FileAttributes - { - return $this->adapter->fileSize($path); - } - - public function listContents(string $path, bool $deep): iterable - { - return $this->adapter->listContents($path, $deep); - } - public function move(string $source, string $destination, Config $config): void { throw new UnableToMoveFile("Unable to move file from $source to $destination as this is a readonly adapter.");