diff options
author | icewind1991 <robin@icewind.nl> | 2014-05-30 14:58:59 +0200 |
---|---|---|
committer | icewind1991 <robin@icewind.nl> | 2014-05-30 14:58:59 +0200 |
commit | 2ba5701b1af3ba37061fa0e5fa85aac7abaabea4 (patch) | |
tree | 880ca8c8cfbf48a103b42571645668eb918898c1 | |
parent | 517501ffbf369b24191d8b9a9f2ce44a9891fb97 (diff) | |
parent | 998fa2d9be4a876cec00073b0706a793276ddd8f (diff) | |
download | nextcloud-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
-rw-r--r-- | apps/files_sharing/lib/proxy.php | 2 | ||||
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 2 | ||||
-rw-r--r-- | lib/private/files/mount/mount.php | 2 | ||||
-rw-r--r-- | lib/private/files/storage/common.php | 14 | ||||
-rw-r--r-- | lib/private/files/storage/wrapper/wrapper.php | 21 | ||||
-rwxr-xr-x | lib/private/util.php | 5 | ||||
-rw-r--r-- | lib/public/files/storage.php | 8 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 6 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper/quota.php | 6 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper/wrapper.php | 5 |
10 files changed, 65 insertions, 6 deletions
diff --git a/apps/files_sharing/lib/proxy.php b/apps/files_sharing/lib/proxy.php index c899a4b4dd3..f595328cc63 100644 --- a/apps/files_sharing/lib/proxy.php +++ b/apps/files_sharing/lib/proxy.php @@ -57,7 +57,7 @@ class Proxy extends \OC_FileProxy { $mountManager = \OC\Files\Filesystem::getMountManager(); $mountedShares = $mountManager->findIn($path); foreach ($mountedShares as $mount) { - if ($mount->getStorage() instanceof \OC\Files\Storage\Shared) { + if ($mount->getStorage()->instanceOfStorage('\OC\Files\Storage\Shared')) { $mountPoint = $mount->getMountPoint(); $mountPointName = $mount->getMountPointName(); $target = \OCA\Files_Sharing\Helper::generateUniqueTarget(dirname($path) . '/' . $mountPointName, array(), $view); diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 67ccbd13403..a7dd2b3afa1 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -300,7 +300,7 @@ class Shared extends \OC\Files\Storage\Common { // it shouldn't be possible to move a Shared storage into another one list($targetStorage, ) = \OC\Files\Filesystem::resolvePath($targetPath); - if ($targetStorage instanceof \OC\Files\Storage\Shared) { + if ($targetStorage->instanceOfStorage('\OC\Files\Storage\Shared')) { \OCP\Util::writeLog('file sharing', 'It is not allowed to move one mount point into another one', \OCP\Util::DEBUG); 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); } diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 24390f05367..dd73491d7ee 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -464,4 +464,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); } + + 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 777529fd85e..954fe199cc8 100644 --- a/tests/lib/files/storage/wrapper/quota.php +++ b/tests/lib/files/storage/wrapper/quota.php @@ -155,4 +155,10 @@ class Quota extends \Test\Files\Storage\Storage { $this->assertEquals(1024 - 50, $instance->free_space('')); } + + 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 e31abfc7324..8bcf42035d4 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')); + } } |