diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-01-10 13:36:51 +0300 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2022-01-14 17:17:01 +0300 |
commit | 79289c55f22d5c6c1a7190d4b683352c9f5faca3 (patch) | |
tree | 89e229683699e809d2838c91c149027bacb40b54 /lib | |
parent | 7a6612b809a815076ed022767767eac564873a4c (diff) |
Add helper method in Wrapper
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Wrapper.php | 21 |
1 files changed, 20 insertions, 1 deletions
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) { @@ -498,6 +498,25 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea } /** + * @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 * * @param string $method |