From 79289c55f22d5c6c1a7190d4b683352c9f5faca3 Mon Sep 17 00:00:00 2001 From: Carl Schwan <carl@carlschwan.eu> Date: Mon, 10 Jan 2022 11:36:51 +0100 Subject: Add helper method in Wrapper Signed-off-by: Carl Schwan <carl@carlschwan.eu> --- lib/private/Files/Storage/Wrapper/Wrapper.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index ec1da92f317..ffea74dfcac 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -486,7 +486,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea /** * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class * - * @param string $class + * @param class-string<IStorage> $class * @return bool */ public function instanceOfStorage($class) { @@ -497,6 +497,25 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return is_a($this, $class) or $this->getWrapperStorage()->instanceOfStorage($class); } + /** + * @template T of IStorage + * @param class-string<T> $class + * @return ?T + */ + public function getInstanceOfStorage(string $class): ?IStorage { + $storage = $this; + while ($storage->instanceOfStorage(Wrapper::class)) { + if ($storage instanceof $class) { + break; + } + $storage = $storage->getWrapperStorage(); + } + if (!is_a($storage, $class)) { + return null; + } + return $storage; + } + /** * Pass any methods custom to specific storage implementations to the wrapped storage * -- cgit v1.2.3