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
This commit is contained in:
Robin McCorkell 2015-08-12 21:43:29 +01:00
parent 97dbc79c16
commit c592e24c87
6 changed files with 25 additions and 32 deletions

View file

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

View file

@ -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(

View file

@ -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 */

View file

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

View file

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

View file

@ -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() {