summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-05 12:16:36 +0100
committerGitHub <noreply@github.com>2018-11-05 12:16:36 +0100
commitcba3883410f958305673f75950c5b6227c571f16 (patch)
tree50c627bd8a4d60daa8ae968e64c96b40509e39b7 /lib/private
parent934d08b2e8b0f6f8616882b9c08d1bec4db22eb2 (diff)
parentc8cf98652730391dcab1e25494981a901c25ca8d (diff)
downloadnextcloud-server-cba3883410f958305673f75950c5b6227c571f16.tar.gz
nextcloud-server-cba3883410f958305673f75950c5b6227c571f16.zip
Merge pull request #12185 from nextcloud/cleanup/dicontainer
Cleanup the DIContainer
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/AppFramework/App.php4
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php57
-rw-r--r--lib/private/AppFramework/Utility/SimpleContainer.php1
-rw-r--r--lib/private/Server.php17
4 files changed, 28 insertions, 51 deletions
diff --git a/lib/private/AppFramework/App.php b/lib/private/AppFramework/App.php
index 25708245e26..abb779ca979 100644
--- a/lib/private/AppFramework/App.php
+++ b/lib/private/AppFramework/App.php
@@ -84,9 +84,9 @@ class App {
*/
public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) {
if (!is_null($urlParams)) {
- $container[IRequest::class]->setUrlParameters($urlParams);
+ $container->query(IRequest::class)->setUrlParameters($urlParams);
} else if (isset($container['urlParams']) && !is_null($container['urlParams'])) {
- $container[IRequest::class]->setUrlParameters($container['urlParams']);
+ $container->query(IRequest::class)->setUrlParameters($container['urlParams']);
}
$appName = $container['AppName'];
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index 439404f26ce..3708d967c9d 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -46,15 +46,13 @@ use OC\AppFramework\Middleware\Security\RateLimitingMiddleware;
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
use OC\AppFramework\Middleware\SessionMiddleware;
use OC\AppFramework\Utility\SimpleContainer;
-use OC\Collaboration\Collaborators\SearchResult;
use OC\Core\Middleware\TwoFactorMiddleware;
-use OC\RichObjectStrings\Validator;
use OC\ServerContainer;
use OCP\AppFramework\Http\IOutput;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\QueryException;
+use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Files\Folder;
use OCP\Files\IAppData;
use OCP\GlobalScale\IConfig;
@@ -64,8 +62,6 @@ use OCP\IRequest;
use OCP\IServerContainer;
use OCP\ISession;
use OCP\IUserSession;
-use OCP\RichObjectStrings\IValidator;
-use OCP\Encryption\IManager;
use OCA\WorkflowEngine\Manager;
class DIContainer extends SimpleContainer implements IAppContainer {
@@ -89,6 +85,8 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this['AppName'] = $appName;
$this['urlParams'] = $urlParams;
+ $this->registerAlias('Request', IRequest::class);
+
/** @var \OC\ServerContainer $server */
if ($server === null) {
$server = \OC::$server;
@@ -125,19 +123,6 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName'));
});
- $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
- $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
-
- $this->registerService(IRequest::class, function() {
- return $this->getServer()->query(IRequest::class);
- });
- $this->registerAlias('Request', IRequest::class);
-
- $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
- $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
-
- $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
-
$this->registerService(IServerContainer::class, function ($c) {
return $this->getServer();
});
@@ -151,8 +136,6 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $c;
});
- $this->registerAlias(ISearchResult::class, SearchResult::class);
-
// commonly used attributes
$this->registerService('UserId', function ($c) {
return $c->query(IUserSession::class)->getSession()->get('user_id');
@@ -166,26 +149,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $c->getServer()->getThemingDefaults();
});
- $this->registerService(IManager::class, function ($c) {
- return $this->getServer()->getEncryptionManager();
- });
-
$this->registerService(IConfig::class, function ($c) {
return $c->query(OC\GlobalScale\Config::class);
});
- $this->registerService(IValidator::class, function($c) {
- return $c->query(Validator::class);
- });
-
- $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
- return new \OC\Security\IdentityProof\Manager(
- $this->getServer()->query(\OC\Files\AppData\Factory::class),
- $this->getServer()->getCrypto(),
- $this->getServer()->getConfig()
- );
- });
-
$this->registerService('Protocol', function($c){
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
@@ -197,7 +164,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return new Dispatcher(
$c['Protocol'],
$c['MiddlewareDispatcher'],
- $c['ControllerMethodReflector'],
+ $c->query(IControllerMethodReflector::class),
$c['Request']
);
});
@@ -219,7 +186,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return new SecurityMiddleware(
$c['Request'],
- $c['ControllerMethodReflector'],
+ $server->query(IControllerMethodReflector::class),
$server->getNavigationManager(),
$server->getURLGenerator(),
$server->getLogger(),
@@ -239,7 +206,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$server = $app->getServer();
return new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware(
- $c['ControllerMethodReflector'],
+ $c->query(IControllerMethodReflector::class),
$server->getSession(),
$server->getUserSession(),
$server->query(ITimeFactory::class)
@@ -251,7 +218,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$server = $app->getServer();
return new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
- $c['ControllerMethodReflector'],
+ $c->query(IControllerMethodReflector::class),
$server->getBruteForceThrottler(),
$server->getRequest()
);
@@ -264,7 +231,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return new RateLimitingMiddleware(
$server->getRequest(),
$server->getUserSession(),
- $c['ControllerMethodReflector'],
+ $c->query(IControllerMethodReflector::class),
$c->query(OC\Security\RateLimiting\Limiter::class)
);
});
@@ -272,7 +239,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this->registerService('CORSMiddleware', function($c) {
return new CORSMiddleware(
$c['Request'],
- $c['ControllerMethodReflector'],
+ $c->query(IControllerMethodReflector::class),
$c->query(IUserSession::class),
$c->getServer()->getBruteForceThrottler()
);
@@ -281,7 +248,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this->registerService('SessionMiddleware', function($c) use ($app) {
return new SessionMiddleware(
$c['Request'],
- $c['ControllerMethodReflector'],
+ $c->query(IControllerMethodReflector::class),
$app->getServer()->getSession()
);
});
@@ -291,7 +258,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$userSession = $app->getServer()->getUserSession();
$session = $app->getServer()->getSession();
$urlGenerator = $app->getServer()->getURLGenerator();
- $reflector = $c['ControllerMethodReflector'];
+ $reflector = $c->query(IControllerMethodReflector::class);
$request = $app->getServer()->getRequest();
return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
});
@@ -305,7 +272,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) {
return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
$c['Request'],
- $c['ControllerMethodReflector']
+ $c->query(IControllerMethodReflector::class)
);
});
diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php
index 47a6f95f747..6c2844e681b 100644
--- a/lib/private/AppFramework/Utility/SimpleContainer.php
+++ b/lib/private/AppFramework/Utility/SimpleContainer.php
@@ -176,5 +176,4 @@ class SimpleContainer extends Container implements IContainer {
}
return $name;
}
-
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 204345708b9..938c54b8a1c 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -217,7 +217,7 @@ class Server extends ServerContainer implements IServerContainer {
);
});
- $this->registerService('EncryptionManager', function (Server $c) {
+ $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
$view = new View();
$util = new Encryption\Util(
$view,
@@ -234,6 +234,7 @@ class Server extends ServerContainer implements IServerContainer {
new ArrayCache()
);
});
+ $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
$this->registerService('EncryptionFileHelper', function (Server $c) {
$util = new Encryption\Util(
@@ -361,7 +362,7 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
- $this->registerService(\OCP\IUserSession::class, function (Server $c) {
+ $this->registerService(\OC\User\Session::class, function (Server $c) {
$manager = $c->getUserManager();
$session = new \OC\Session\Memory('');
$timeFactory = new TimeFactory();
@@ -430,7 +431,8 @@ class Server extends ServerContainer implements IServerContainer {
});
return $userSession;
});
- $this->registerAlias('UserSession', \OCP\IUserSession::class);
+ $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
+ $this->registerAlias('UserSession', \OC\User\Session::class);
$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
@@ -1083,6 +1085,7 @@ class Server extends ServerContainer implements IServerContainer {
return $instance;
});
$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
+ $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
@@ -1188,6 +1191,14 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(IDashboardManager::class, DashboardManager::class);
$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
+ $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
+ return new \OC\Security\IdentityProof\Manager(
+ $c->query(\OC\Files\AppData\Factory::class),
+ $c->getCrypto(),
+ $c->getConfig()
+ );
+ });
+
$this->connectDispatcher();
}