[Pkg-owncloud-commits] [owncloud] 35/85: Add ->instanceOfStorage to handle instanceof for storage wrappers
David Prévot
taffit at moszumanska.debian.org
Tue Jun 17 19:12:42 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch 6.0
in repository owncloud.
commit 79b953a9200f653bc2dcdd395dbb14e1df79ad75
Author: Robin Appelman <icewind at owncloud.com>
Date: Thu May 29 13:45:50 2014 +0200
Add ->instanceOfStorage to handle instanceof for storage wrappers
---
lib/private/files/storage/common.php | 11 ++++++++++-
lib/private/files/storage/wrapper/wrapper.php | 10 ++++++++++
lib/public/files/storage.php | 8 ++++++++
tests/lib/files/storage/storage.php | 6 ++++++
tests/lib/files/storage/wrapper/quota.php | 6 ++++++
tests/lib/files/storage/wrapper/wrapper.php | 5 +++++
6 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 678bf41..dd5cc91 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -19,7 +19,6 @@ namespace OC\Files\Storage;
* 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;
@@ -370,4 +369,14 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function free_space($path) {
return \OC\Files\SPACE_UNKNOWN;
}
+
+ /**
+ * 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 f9adda8..3e77b0b 100644
--- a/lib/private/files/storage/wrapper/wrapper.php
+++ b/lib/private/files/storage/wrapper/wrapper.php
@@ -432,4 +432,14 @@ class Wrapper implements \OC\Files\Storage\Storage {
public function test() {
return $this->storage->test();
}
+
+ /**
+ * 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);
+ }
}
diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php
index 194b42a..9bed49c 100644
--- a/lib/public/files/storage.php
+++ b/lib/public/files/storage.php
@@ -315,4 +315,12 @@ interface Storage {
* @return string
*/
public function getETag($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);
}
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index 182c014..196cd01 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -279,4 +279,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->instance->file_exists('folder/bar'));
$this->assertFalse($this->instance->file_exists('folder'));
}
+
+ public function testInstanceOfStorage() {
+ $this->assertTrue($this->instance->instanceOfStorage('\OCP\Files\Storage'));
+ $this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance)));
+ $this->assertFalse($this->instance->instanceOfStorage('\OC'));
+ }
}
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index ccf2a8c..2c87800 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -133,4 +133,10 @@ class Quota extends \Test\Files\Storage\Storage {
$this->assertEquals('user-space', $meta['wrapper_type']);
fclose($stream);
}
+
+ public function testInstanceOfStorageWrapper() {
+ $this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Local'));
+ $this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Wrapper\Wrapper'));
+ $this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota'));
+ }
}
diff --git a/tests/lib/files/storage/wrapper/wrapper.php b/tests/lib/files/storage/wrapper/wrapper.php
index e31abfc..8bcf420 100644
--- a/tests/lib/files/storage/wrapper/wrapper.php
+++ b/tests/lib/files/storage/wrapper/wrapper.php
@@ -23,4 +23,9 @@ class Wrapper extends \Test\Files\Storage\Storage {
public function tearDown() {
\OC_Helper::rmdirr($this->tmpDir);
}
+
+ public function testInstanceOfStorageWrapper() {
+ $this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Local'));
+ $this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Wrapper\Wrapper'));
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list