diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-05-08 22:35:10 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-05-08 22:35:10 +0200 |
commit | d97ef0805ba5c5687e0642bb8f7c085966153ac9 (patch) | |
tree | 0e4aa6c16637861282e7d8f15e475d5cc206605c /lib | |
parent | ba9db1964053be769b42452fee65ac4720489f81 (diff) | |
download | nextcloud-server-d97ef0805ba5c5687e0642bb8f7c085966153ac9.tar.gz nextcloud-server-d97ef0805ba5c5687e0642bb8f7c085966153ac9.zip |
Add mechanism to allow apps to wraper storage classes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/files/mount/mount.php | 26 | ||||
-rw-r--r-- | lib/files/storage/loader.php | 17 |
2 files changed, 42 insertions, 1 deletions
diff --git a/lib/files/mount/mount.php b/lib/files/mount/mount.php index 69b8285ab4c..d25a7b3be6e 100644 --- a/lib/files/mount/mount.php +++ b/lib/files/mount/mount.php @@ -23,6 +23,11 @@ class Mount { private $mountPoint; /** + * @var callable[] $storageWrappers + */ + private $storageWrappers = array(); + + /** * @param string|\OC\Files\Storage\Storage $storage * @param string $mountpoint * @param array $arguments (optional) @@ -62,7 +67,7 @@ class Mount { private function createStorage() { if (class_exists($this->class)) { try { - return new $this->class($this->arguments); + return $this->loadStorage($this->class, $this->arguments); } catch (\Exception $exception) { \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR); return null; @@ -74,6 +79,25 @@ 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() { diff --git a/lib/files/storage/loader.php b/lib/files/storage/loader.php new file mode 100644 index 00000000000..7330cae4cc4 --- /dev/null +++ b/lib/files/storage/loader.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Storage; + +class Loader { + private function $wrappers + + public function load($class, $arguments) { + return new $class($arguments); + } +} |