diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-06-07 17:07:13 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-06-07 17:07:13 +0200 |
commit | bd675124096707a925faac2774516975ec7049c1 (patch) | |
tree | 795bb623392030c23d18ad466df6596f96f4b62b /lib/files/mount | |
parent | d97ef0805ba5c5687e0642bb8f7c085966153ac9 (diff) | |
download | nextcloud-server-bd675124096707a925faac2774516975ec7049c1.tar.gz nextcloud-server-bd675124096707a925faac2774516975ec7049c1.zip |
manage creating and wrapping storages in it's own class
Diffstat (limited to 'lib/files/mount')
-rw-r--r-- | lib/files/mount/mount.php | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/lib/files/mount/mount.php b/lib/files/mount/mount.php index d25a7b3be6e..17b0055ee84 100644 --- a/lib/files/mount/mount.php +++ b/lib/files/mount/mount.php @@ -9,10 +9,10 @@ namespace OC\Files\Mount; use \OC\Files\Filesystem; +use OC\Files\Storage\Loader; +use OC\Files\Storage\Storage; class Mount { - - /** * @var \OC\Files\Storage\Storage $storage */ @@ -23,24 +23,30 @@ class Mount { private $mountPoint; /** - * @var callable[] $storageWrappers + * @var \OC\Files\Storage\Loader $loader */ - private $storageWrappers = array(); + private $loader; /** - * @param string|\OC\Files\Storage\Storage $storage + * @param string | \OC\Files\Storage\Storage $storage * @param string $mountpoint - * @param array $arguments (optional) + * @param array $arguments (optional)\ + * @param \OC\Files\Storage\Loader $loader */ - public function __construct($storage, $mountpoint, $arguments = null) { + public function __construct($storage, $mountpoint, $arguments = null, $loader = null) { if (is_null($arguments)) { $arguments = array(); } + if (is_null($loader)) { + $this->loader = new Loader(); + } else { + $this->loader = $loader; + } $mountpoint = $this->formatPath($mountpoint); - if ($storage instanceof \OC\Files\Storage\Storage) { + if ($storage instanceof Storage) { $this->class = get_class($storage); - $this->storage = $storage; + $this->storage = $this->loader->wrap($mountpoint, $storage); } else { // Update old classes to new namespace if (strpos($storage, 'OC_Filestorage_') !== false) { @@ -67,7 +73,7 @@ class Mount { private function createStorage() { if (class_exists($this->class)) { try { - return $this->loadStorage($this->class, $this->arguments); + return $this->loader->load($this->mountPoint, $this->class, $this->arguments); } catch (\Exception $exception) { \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR); return null; @@ -79,25 +85,6 @@ class Mount { } /** - * allow modifier storage behaviour by adding wrappers around storages - * - * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage - * - * @param callable $callback - */ - public function addStorageWrapper($callback) { - $this->storageWrappers[] = $callback; - } - - private function loadStorage($class, $arguments) { - $storage = new $class($arguments); - foreach ($this->storageWrappers as $wrapper) { - $storage = $wrapper($this->mountPoint, $storage); - } - return $storage; - } - - /** * @return \OC\Files\Storage\Storage */ public function getStorage() { |