summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoricewind1991 <robin@icewind.nl>2014-05-30 14:58:59 +0200
committericewind1991 <robin@icewind.nl>2014-05-30 14:58:59 +0200
commit2ba5701b1af3ba37061fa0e5fa85aac7abaabea4 (patch)
tree880ca8c8cfbf48a103b42571645668eb918898c1 /lib
parent517501ffbf369b24191d8b9a9f2ce44a9891fb97 (diff)
parent998fa2d9be4a876cec00073b0706a793276ddd8f (diff)
downloadnextcloud-server-2ba5701b1af3ba37061fa0e5fa85aac7abaabea4.tar.gz
nextcloud-server-2ba5701b1af3ba37061fa0e5fa85aac7abaabea4.zip
Merge pull request #8778 from owncloud/storage-instanceof
Add storage->instanceOfStorage() to handle instanceof with storage wrappers
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/mount/mount.php2
-rw-r--r--lib/private/files/storage/common.php14
-rw-r--r--lib/private/files/storage/wrapper/wrapper.php21
-rwxr-xr-xlib/private/util.php5
-rw-r--r--lib/public/files/storage.php8
5 files changed, 46 insertions, 4 deletions
diff --git a/lib/private/files/mount/mount.php b/lib/private/files/mount/mount.php
index d4a4e186fb9..7c40853ac95 100644
--- a/lib/private/files/mount/mount.php
+++ b/lib/private/files/mount/mount.php
@@ -161,6 +161,6 @@ class Mount {
* @param callable $wrapper
*/
public function wrapStorage($wrapper) {
- $this->storage = $wrapper($this->mountPoint, $this->storage);
+ $this->storage = $wrapper($this->mountPoint, $this->getStorage());
}
}
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..364475a68e0 100644
--- a/lib/private/files/storage/wrapper/wrapper.php
+++ b/lib/private/files/storage/wrapper/wrapper.php
@@ -440,4 +440,25 @@ 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);
+ }
+
+ /**
+ * 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);
+ }
}
diff --git a/lib/private/util.php b/lib/private/util.php
index 23c7053002c..bf7f39ebb20 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -57,7 +57,10 @@ class OC_Util {
// set up quota for home storages, even for other users
// which can happen when using sharing
- if ($storage instanceof \OC\Files\Storage\Home) {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ if ($storage->instanceOfStorage('\OC\Files\Storage\Home')) {
$user = $storage->getUser()->getUID();
$quota = OC_Util::getUserQuota($user);
if ($quota !== \OC\Files\SPACE_UNLIMITED) {
diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php
index 5ec8ac6245c..323d20db564 100644
--- a/lib/public/files/storage.php
+++ b/lib/public/files/storage.php
@@ -327,4 +327,12 @@ interface Storage {
* @return bool true if the files are stored locally, false otherwise
*/
public function 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);
}