From 8c5521fdfc2e9e85037c61cd77a254e3b7cd1b94 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 29 May 2014 13:45:50 +0200 Subject: Add $storage->instanceOfStorage to handle instanceof for storage wrappers --- lib/private/files/storage/common.php | 14 ++++++++++++-- lib/private/files/storage/wrapper/wrapper.php | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'lib/private/files/storage') diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 1ed0d79817b..6b11603323a 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -7,6 +7,7 @@ */ namespace OC\Files\Storage; + use OC\Files\Filesystem; use OC\Files\Cache\Watcher; @@ -21,7 +22,6 @@ use OC\Files\Cache\Watcher; * Some \OC\Files\Storage\Common methods call functions which are first defined * in classes which extend it, e.g. $this->stat() . */ - abstract class Common implements \OC\Files\Storage\Storage { protected $cache; protected $scanner; @@ -46,7 +46,7 @@ abstract class Common implements \OC\Files\Storage\Storage { protected function remove($path) { if ($this->is_dir($path)) { return $this->rmdir($path); - } else if($this->is_file($path)) { + } else if ($this->is_file($path)) { return $this->unlink($path); } else { return false; @@ -412,4 +412,14 @@ abstract class Common implements \OC\Files\Storage\Storage { protected function removeCachedFile($path) { unset($this->cachedFiles[$path]); } + + /** + * 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 + * @return bool + */ + public function instanceOfStorage($class) { + return is_a($this, $class); + } } diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index 11ea9f71da7..dd2f76e05b8 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -440,4 +440,14 @@ class Wrapper implements \OC\Files\Storage\Storage { public function isLocal() { return $this->storage->isLocal(); } + + /** + * 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 + * @return bool + */ + public function instanceOfStorage($class) { + return is_a($this, $class) or $this->storage->instanceOfStorage($class); + } } -- cgit v1.2.3 From 998fa2d9be4a876cec00073b0706a793276ddd8f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 29 May 2014 16:13:05 +0200 Subject: Pass any methods custom to specific storage implementations to the wrapped storage --- lib/private/files/storage/wrapper/wrapper.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/private/files/storage') diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index dd2f76e05b8..364475a68e0 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -450,4 +450,15 @@ class Wrapper implements \OC\Files\Storage\Storage { public function instanceOfStorage($class) { return is_a($this, $class) or $this->storage->instanceOfStorage($class); } + + /** + * Pass any methods custom to specific storage implementations to the wrapped storage + * + * @param string $method + * @param array $args + * @return mixed + */ + public function __call($method, $args) { + return call_user_func_array(array($this->storage, $method), $args); + } } -- cgit v1.2.3