diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-01-10 11:36:51 +0100 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-01-13 10:39:36 +0100 |
commit | 695165260f26b2f5b5584e619e54741db1a2d9cc (patch) | |
tree | f54ef011bcdc40a4062d03e3a866cf55be14531f /lib/private/Files/Storage/Wrapper | |
parent | 0479fff37cb08157d982c593ce21fb79957e8574 (diff) | |
download | nextcloud-server-695165260f26b2f5b5584e619e54741db1a2d9cc.tar.gz nextcloud-server-695165260f26b2f5b5584e619e54741db1a2d9cc.zip |
Add helper method in Wrapper
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/private/Files/Storage/Wrapper')
-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 5faffece67e..b44db7c13ce 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 |