summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-08-12 21:43:29 +0100
committerRobin McCorkell <rmccorkell@owncloud.com>2015-08-19 10:08:23 +0100
commitc592e24c871f0f6a8d688c5c93e769b1505e4b6d (patch)
tree0b967704610d193c1296ae623ab2b7212e87e2d0 /apps/files_external
parent97dbc79c16ba9d4d6c361d6f397908ef7893954d (diff)
downloadnextcloud-server-c592e24c871f0f6a8d688c5c93e769b1505e4b6d.tar.gz
nextcloud-server-c592e24c871f0f6a8d688c5c93e769b1505e4b6d.zip
Make Application a singleton
The same Application must be used in the settings templates and in routes, so that any registered backends are correctly seen
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/appinfo/app.php8
-rw-r--r--apps/files_external/appinfo/routes.php3
-rw-r--r--apps/files_external/lib/config.php31
-rw-r--r--apps/files_external/personal.php4
-rw-r--r--apps/files_external/settings.php4
-rw-r--r--apps/files_external/tests/service/storagesservicetest.php7
6 files changed, 25 insertions, 32 deletions
diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php
index 37a489535ea..6c659af8aac 100644
--- a/apps/files_external/appinfo/app.php
+++ b/apps/files_external/appinfo/app.php
@@ -47,8 +47,9 @@ OC::$CLASSPATH['OCA\Files\External\Api'] = 'files_external/lib/api.php';
require_once __DIR__ . '/../3rdparty/autoload.php';
-$app = new \OCA\Files_external\Appinfo\Application();
-$appContainer = $app->getContainer();
+// register Application object singleton
+\OC_Mount_Config::$app = new \OCA\Files_external\Appinfo\Application();
+$appContainer = \OC_Mount_Config::$app->getContainer();
$l = \OC::$server->getL10N('files_external');
@@ -65,9 +66,6 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == '
"name" => $l->t('External storage')
]);
-// Teach OC_Mount_Config about the AppFramework
-\OC_Mount_Config::initApp($appContainer);
-
// connecting hooks
OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook');
OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login');
diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php
index bc4b0e98c91..213e7b28dc1 100644
--- a/apps/files_external/appinfo/routes.php
+++ b/apps/files_external/appinfo/routes.php
@@ -28,8 +28,7 @@ namespace OCA\Files_External\AppInfo;
/**
* @var $this \OC\Route\Router
**/
-$application = new Application();
-$application->registerRoutes(
+\OC_Mount_Config::$app->registerRoutes(
$this,
array(
'resources' => array(
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 6fdf050fb60..5c38a3ba0cb 100644
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -32,7 +32,7 @@
*/
use phpseclib\Crypt\AES;
-use \OCP\AppFramework\IAppContainer;
+use \OCA\Files_External\Appinfo\Application;
use \OCA\Files_External\Lib\BackendConfig;
use \OCA\Files_External\Service\BackendService;
use \OCA\Files_External\Lib\Backend\LegacyBackend;
@@ -56,17 +56,8 @@ class OC_Mount_Config {
// whether to skip backend test (for unit tests, as this static class is not mockable)
public static $skipTest = false;
- /** @var IAppContainer */
- private static $appContainer;
-
- /**
- * Teach OC_Mount_Config about the AppFramework
- *
- * @param IAppContainer $appContainer
- */
- public static function initApp(IAppContainer $appContainer) {
- self::$appContainer = $appContainer;
- }
+ /** @var Application */
+ public static $app;
/**
* @param string $class
@@ -75,8 +66,8 @@ class OC_Mount_Config {
* @deprecated 8.2.0 use \OCA\Files_External\Service\BackendService::registerBackend()
*/
public static function registerBackend($class, $definition) {
- $backendService = self::$appContainer->query('OCA\Files_External\Service\BackendService');
- $auth = self::$appContainer->query('OCA\Files_External\Lib\Auth\Builtin');
+ $backendService = self::$app->getContainer()->query('OCA\Files_External\Service\BackendService');
+ $auth = self::$app->getContainer()->query('OCA\Files_External\Lib\Auth\Builtin');
$backendService->registerBackend(new LegacyBackend($class, $definition, $auth));
@@ -128,9 +119,9 @@ class OC_Mount_Config {
public static function getAbsoluteMountPoints($uid) {
$mountPoints = array();
- $userGlobalStoragesService = self::$appContainer->query('OCA\Files_External\Service\UserGlobalStoragesService');
- $userStoragesService = self::$appContainer->query('OCA\Files_External\Service\UserStoragesService');
- $user = self::$appContainer->query('OCP\IUserManager')->get($uid);
+ $userGlobalStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserGlobalStoragesService');
+ $userStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService');
+ $user = self::$app->getContainer()->query('OCP\IUserManager')->get($uid);
$userGlobalStoragesService->setUser($user);
$userStoragesService->setUser($user);
@@ -168,7 +159,7 @@ class OC_Mount_Config {
*/
public static function getSystemMountPoints() {
$mountPoints = [];
- $service = self::$appContainer->query('OCA\Files_External\Service\GlobalStoragesService');
+ $service = self::$app->getContainer()->query('OCA\Files_External\Service\GlobalStoragesService');
foreach ($service->getAllStorages() as $storage) {
$mountPoints[] = self::prepareMountPointEntry($storage, false);
@@ -184,7 +175,7 @@ class OC_Mount_Config {
*/
public static function getPersonalMountPoints() {
$mountPoints = [];
- $service = self::$appContainer->query('OCA\Files_External\Service\UserStoragesService');
+ $service = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService');
foreach ($service->getAllStorages() as $storage) {
$mountPoints[] = self::prepareMountPointEntry($storage, true);
@@ -533,7 +524,7 @@ class OC_Mount_Config {
return false;
}
- $service = self::$appContainer->query('OCA\Files_External\Service\BackendService');
+ $service = self::$app->getContainer()->query('OCA\Files_External\Service\BackendService');
$class = $service->getBackend($options['backend'])->getStorageClass();
try {
/** @var \OC\Files\Storage\Storage $storage */
diff --git a/apps/files_external/personal.php b/apps/files_external/personal.php
index fec1c195bba..696ca51b2ed 100644
--- a/apps/files_external/personal.php
+++ b/apps/files_external/personal.php
@@ -26,8 +26,8 @@
use \OCA\Files_External\Service\BackendService;
-$app = new \OCA\Files_external\Appinfo\Application();
-$appContainer = $app->getContainer();
+// we must use the same container
+$appContainer = \OC_Mount_Config::$app->getContainer();
$backendService = $appContainer->query('OCA\Files_External\Service\BackendService');
$userStoragesService = $appContainer->query('OCA\Files_external\Service\UserStoragesService');
diff --git a/apps/files_external/settings.php b/apps/files_external/settings.php
index 7e20af0c60d..2ad31a31137 100644
--- a/apps/files_external/settings.php
+++ b/apps/files_external/settings.php
@@ -30,8 +30,8 @@ use \OCA\Files_External\Service\BackendService;
OC_Util::checkAdminUser();
-$app = new \OCA\Files_external\Appinfo\Application();
-$appContainer = $app->getContainer();
+// we must use the same container
+$appContainer = \OC_Mount_Config::$app->getContainer();
$backendService = $appContainer->query('OCA\Files_External\Service\BackendService');
$globalStoragesService = $appContainer->query('OCA\Files_external\Service\GlobalStoragesService');
diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php
index 07286106c7b..28220c9bc2e 100644
--- a/apps/files_external/tests/service/storagesservicetest.php
+++ b/apps/files_external/tests/service/storagesservicetest.php
@@ -121,7 +121,12 @@ abstract class StoragesServiceTest extends \Test\TestCase {
return $this->backendService;
}
}));
- \OC_Mount_Config::initApp($containerMock);
+
+ \OC_Mount_Config::$app = $this->getMockBuilder('\OCA\Files_External\Appinfo\Application')
+ ->disableOriginalConstructor()
+ ->getMock();
+ \OC_Mount_Config::$app->method('getContainer')
+ ->willReturn($containerMock);
}
public function tearDown() {