Add mechanism to allow apps to wraper storage classes

This commit is contained in:
Robin Appelman 2013-05-08 22:35:10 +02:00
parent ba9db19640
commit d97ef0805b
2 changed files with 42 additions and 1 deletions

View File

@ -22,6 +22,11 @@ class Mount {
private $arguments = array();
private $mountPoint;
/**
* @var callable[] $storageWrappers
*/
private $storageWrappers = array();
/**
* @param string|\OC\Files\Storage\Storage $storage
* @param string $mountpoint
@ -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;
@ -73,6 +78,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
*/

View File

@ -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);
}
}