Skip to content
Snippets Groups Projects
Commit d97ef080 authored by Robin Appelman's avatar Robin Appelman
Browse files

Add mechanism to allow apps to wraper storage classes

parent ba9db196
Branches
No related tags found
No related merge requests found
...@@ -22,6 +22,11 @@ class Mount { ...@@ -22,6 +22,11 @@ class Mount {
private $arguments = array(); private $arguments = array();
private $mountPoint; private $mountPoint;
/**
* @var callable[] $storageWrappers
*/
private $storageWrappers = array();
/** /**
* @param string|\OC\Files\Storage\Storage $storage * @param string|\OC\Files\Storage\Storage $storage
* @param string $mountpoint * @param string $mountpoint
...@@ -62,7 +67,7 @@ class Mount { ...@@ -62,7 +67,7 @@ class Mount {
private function createStorage() { private function createStorage() {
if (class_exists($this->class)) { if (class_exists($this->class)) {
try { try {
return new $this->class($this->arguments); return $this->loadStorage($this->class, $this->arguments);
} catch (\Exception $exception) { } catch (\Exception $exception) {
\OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR); \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR);
return null; return null;
...@@ -73,6 +78,25 @@ class Mount { ...@@ -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 * @return \OC\Files\Storage\Storage
*/ */
......
<?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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment