pass mountpoint to storage wrapper callback

This commit is contained in:
Robin Appelman 2015-03-05 12:28:17 +01:00
parent dbade19362
commit e5c8fd37df
3 changed files with 13 additions and 10 deletions

View File

@ -71,9 +71,10 @@ class MountPoint implements IMountPoint {
} }
$mountpoint = $this->formatPath($mountpoint); $mountpoint = $this->formatPath($mountpoint);
$this->mountPoint = $mountpoint;
if ($storage instanceof Storage) { if ($storage instanceof Storage) {
$this->class = get_class($storage); $this->class = get_class($storage);
$this->storage = $this->loader->wrap($mountpoint, $storage); $this->storage = $this->loader->wrap($this, $storage);
} else { } else {
// Update old classes to new namespace // Update old classes to new namespace
if (strpos($storage, 'OC_Filestorage_') !== false) { if (strpos($storage, 'OC_Filestorage_') !== false) {
@ -82,7 +83,6 @@ class MountPoint implements IMountPoint {
$this->class = $storage; $this->class = $storage;
$this->arguments = $arguments; $this->arguments = $arguments;
} }
$this->mountPoint = $mountpoint;
} }
/** /**
@ -113,7 +113,7 @@ class MountPoint implements IMountPoint {
if (class_exists($this->class)) { if (class_exists($this->class)) {
try { try {
return $this->loader->getInstance($this->mountPoint, $this->class, $this->arguments); return $this->loader->getInstance($this, $this->class, $this->arguments);
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->invalidStorage = true; $this->invalidStorage = true;
if ($this->mountPoint === '/') { if ($this->mountPoint === '/') {

View File

@ -8,6 +8,8 @@
namespace OC\Files\Storage; namespace OC\Files\Storage;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorageFactory; use OCP\Files\Storage\IStorageFactory;
class StorageFactory implements IStorageFactory { class StorageFactory implements IStorageFactory {
@ -55,23 +57,23 @@ class StorageFactory implements IStorageFactory {
/** /**
* Create an instance of a storage and apply the registered storage wrappers * Create an instance of a storage and apply the registered storage wrappers
* *
* @param string|boolean $mountPoint * @param \OCP\Files\Mount\IMountPoint $mountPoint
* @param string $class * @param string $class
* @param array $arguments * @param array $arguments
* @return \OCP\Files\Storage * @return \OCP\Files\Storage
*/ */
public function getInstance($mountPoint, $class, $arguments) { public function getInstance(IMountPoint $mountPoint, $class, $arguments) {
return $this->wrap($mountPoint, new $class($arguments)); return $this->wrap($mountPoint, new $class($arguments));
} }
/** /**
* @param string|boolean $mountPoint * @param \OCP\Files\Mount\IMountPoint $mountPoint
* @param \OCP\Files\Storage $storage * @param \OCP\Files\Storage $storage
* @return \OCP\Files\Storage * @return \OCP\Files\Storage
*/ */
public function wrap($mountPoint, $storage) { public function wrap(IMountPoint $mountPoint, $storage) {
foreach ($this->storageWrappers as $wrapper) { foreach ($this->storageWrappers as $wrapper) {
$storage = $wrapper($mountPoint, $storage); $storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint);
} }
return $storage; return $storage;
} }

View File

@ -7,6 +7,7 @@
*/ */
namespace OCP\Files\Storage; namespace OCP\Files\Storage;
use OCP\Files\Mount\IMountPoint;
/** /**
* Creates storage instances and manages and applies storage wrappers * Creates storage instances and manages and applies storage wrappers
@ -25,10 +26,10 @@ interface IStorageFactory {
public function addStorageWrapper($wrapperName, $callback); public function addStorageWrapper($wrapperName, $callback);
/** /**
* @param string|boolean $mountPoint * @param \OCP\Files\Mount\IMountPoint $mountPoint
* @param string $class * @param string $class
* @param array $arguments * @param array $arguments
* @return \OCP\Files\Storage * @return \OCP\Files\Storage
*/ */
public function getInstance($mountPoint, $class, $arguments); public function getInstance(IMountPoint $mountPoint, $class, $arguments);
} }