aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework/DependencyInjection/DIContainer.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/AppFramework/DependencyInjection/DIContainer.php')
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php282
1 files changed, 52 insertions, 230 deletions
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index f1c6b460a92..06825d2dd5e 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -43,15 +43,18 @@ use OC\AppFramework\Middleware\OCSMiddleware;
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
use OC\AppFramework\Middleware\SessionMiddleware;
use OC\AppFramework\Utility\SimpleContainer;
-use OC\AppFramework\Utility\TimeFactory;
use OC\Core\Middleware\TwoFactorMiddleware;
use OC\RichObjectStrings\Validator;
-use OC\Security\Bruteforce\Throttler;
+use OC\ServerContainer;
+use OCP\AppFramework\Http\IOutput;
use OCP\AppFramework\IApi;
use OCP\AppFramework\IAppContainer;
-use OCP\Federation\ICloudIdManager;
+use OCP\Files\Folder;
use OCP\Files\IAppData;
-use OCP\Files\Mount\IMountManager;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IServerContainer;
+use OCP\IUserSession;
use OCP\RichObjectStrings\IValidator;
use OCP\Util;
@@ -62,18 +65,26 @@ class DIContainer extends SimpleContainer implements IAppContainer {
*/
private $middleWares = array();
+ /** @var ServerContainer */
+ private $server;
+
/**
* Put your class dependencies in here
* @param string $appName the name of the app
+ * @param array $urlParams
+ * @param ServerContainer $server
*/
- public function __construct($appName, $urlParams = array()){
+ public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
parent::__construct();
$this['AppName'] = $appName;
$this['urlParams'] = $urlParams;
/** @var \OC\ServerContainer $server */
- $server = $this->getServer();
- $server->registerAppContainer($appName, $this);
+ if ($server === null) {
+ $server = \OC::$server;
+ }
+ $this->server = $server;
+ $this->server->registerAppContainer($appName, $this);
// aliases
$this->registerAlias('appName', 'AppName');
@@ -83,253 +94,47 @@ class DIContainer extends SimpleContainer implements IAppContainer {
/**
* Core services
*/
- $this->registerService('OCP\\IAppConfig', function($c) {
- return $this->getServer()->getAppConfig();
- });
-
- $this->registerService('OCP\\App\\IAppManager', function($c) {
- return $this->getServer()->getAppManager();
- });
-
- $this->registerService('OCP\\AppFramework\\Http\\IOutput', function($c){
+ $this->registerService(IOutput::class, function($c){
return new Output($this->getServer()->getWebRoot());
});
- $this->registerService(\OCP\Authentication\LoginCredentials\IStore::class, function() {
- return $this->getServer()->query(\OCP\Authentication\LoginCredentials\IStore::class);
- });
-
- $this->registerService('OCP\\IAvatarManager', function($c) {
- return $this->getServer()->getAvatarManager();
- });
-
- $this->registerService('OCP\\Activity\\IManager', function($c) {
- return $this->getServer()->getActivityManager();
- });
- $this->registerService(\OCP\Activity\IEventMerger::class, function($c) {
- return $this->getServer()->query(\OCP\Activity\IEventMerger::class);
- });
-
- $this->registerService('OCP\\ICache', function($c) {
- return $this->getServer()->getCache();
- });
-
- $this->registerService('OCP\\ICacheFactory', function($c) {
- return $this->getServer()->getMemCacheFactory();
- });
-
- $this->registerService('OC\\CapabilitiesManager', function($c) {
- return $this->getServer()->getCapabilitiesManager();
- });
-
- $this->registerService('OCP\Comments\ICommentsManager', function($c) {
- return $this->getServer()->getCommentsManager();
- });
-
- $this->registerService('OCP\\IConfig', function($c) {
- return $this->getServer()->getConfig();
- });
-
- $this->registerService('OCP\\Contacts\\IManager', function($c) {
- return $this->getServer()->getContactsManager();
- });
-
- $this->registerService('OCP\\IDateTimeZone', function($c) {
- return $this->getServer()->getDateTimeZone();
- });
-
- $this->registerService('OCP\\IDateTimeFormatter', function($c) {
- return $this->getServer()->getDateTimeFormatter();
- });
-
- $this->registerService('OCP\\IDBConnection', function($c) {
- return $this->getServer()->getDatabaseConnection();
- });
-
- $this->registerService('OCP\\Diagnostics\\IEventLogger', function($c) {
- return $this->getServer()->getEventLogger();
- });
-
- $this->registerService('OCP\\Diagnostics\\IQueryLogger', function($c) {
- return $this->getServer()->getQueryLogger();
- });
-
- $this->registerService(ICloudIdManager::class, function($c) {
- return $this->getServer()->getCloudIdManager();
- });
-
- $this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
- return $this->getServer()->getMimeTypeDetector();
- });
-
- $this->registerService('OCP\\Files\\Config\\IMountProviderCollection', function($c) {
- return $this->getServer()->getMountProviderCollection();
- });
-
- $this->registerService('OCP\\Files\\Config\\IUserMountCache', function($c) {
- return $this->getServer()->getUserMountCache();
- });
-
- $this->registerService('OCP\\Files\\IRootFolder', function($c) {
- return $this->getServer()->getRootFolder();
- });
-
- $this->registerService('OCP\\Files\\Folder', function() {
+ $this->registerService(Folder::class, function() {
return $this->getServer()->getUserFolder();
});
- $this->registerService('OCP\\Http\\Client\\IClientService', function($c) {
- return $this->getServer()->getHTTPClientService();
- });
-
$this->registerService(IAppData::class, function (SimpleContainer $c) {
return $this->getServer()->getAppDataDir($c->query('AppName'));
});
- $this->registerService('OCP\\IGroupManager', function($c) {
- return $this->getServer()->getGroupManager();
- });
-
- $this->registerService('OCP\\Http\\Client\\IClientService', function() {
- return $this->getServer()->getHTTPClientService();
- });
-
- $this->registerService('OCP\\IL10N', function($c) {
+ $this->registerService(IL10N::class, function($c) {
return $this->getServer()->getL10N($c->query('AppName'));
});
- $this->registerService('OCP\\L10N\\IFactory', function($c) {
- return $this->getServer()->getL10NFactory();
- });
-
- $this->registerService('OCP\\ILogger', function($c) {
- return $this->getServer()->getLogger();
- });
+ $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
+ $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
- $this->registerService('OCP\\BackgroundJob\\IJobList', function($c) {
- return $this->getServer()->getJobList();
+ $this->registerService(IRequest::class, function() {
+ return $this->getServer()->query(IRequest::class);
});
+ $this->registerAlias('Request', IRequest::class);
- $this->registerAlias('OCP\\AppFramework\\Utility\\IControllerMethodReflector', 'OC\AppFramework\Utility\ControllerMethodReflector');
- $this->registerAlias('ControllerMethodReflector', 'OCP\\AppFramework\\Utility\\IControllerMethodReflector');
+ $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
+ $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
- $this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) {
- return $this->getServer()->getMimeTypeDetector();
- });
-
- $this->registerService('OCP\\Mail\\IMailer', function() {
- return $this->getServer()->getMailer();
- });
-
- $this->registerService('OCP\\INavigationManager', function($c) {
- return $this->getServer()->getNavigationManager();
- });
-
- $this->registerService('OCP\\Notification\IManager', function($c) {
- return $this->getServer()->getNotificationManager();
- });
-
- $this->registerService('OCP\\IPreview', function($c) {
- return $this->getServer()->getPreviewManager();
- });
-
- $this->registerService('OCP\\IRequest', function () {
- return $this->getServer()->getRequest();
- });
- $this->registerAlias('Request', 'OCP\\IRequest');
-
- $this->registerService('OCP\\ITagManager', function($c) {
- return $this->getServer()->getTagManager();
- });
-
- $this->registerService('OCP\\ITempManager', function($c) {
- return $this->getServer()->getTempManager();
- });
-
- $this->registerAlias('OCP\\AppFramework\\Utility\\ITimeFactory', 'OC\AppFramework\Utility\TimeFactory');
- $this->registerAlias('TimeFactory', 'OCP\\AppFramework\\Utility\\ITimeFactory');
-
-
- $this->registerService('OCP\\Route\\IRouter', function($c) {
- return $this->getServer()->getRouter();
- });
-
- $this->registerService('OCP\\ISearch', function($c) {
- return $this->getServer()->getSearch();
- });
-
- $this->registerService('OCP\\ISearch', function($c) {
- return $this->getServer()->getSearch();
- });
-
- $this->registerService('OCP\\Security\\ICrypto', function($c) {
- return $this->getServer()->getCrypto();
- });
-
- $this->registerService('OCP\\Security\\IHasher', function($c) {
- return $this->getServer()->getHasher();
- });
-
- $this->registerService('OCP\\Security\\ICredentialsManager', function($c) {
- return $this->getServer()->getCredentialsManager();
- });
-
- $this->registerService('OCP\\Security\\ISecureRandom', function($c) {
- return $this->getServer()->getSecureRandom();
- });
-
- $this->registerService('OCP\\Share\\IManager', function($c) {
- return $this->getServer()->getShareManager();
- });
-
- $this->registerService('OCP\\SystemTag\\ISystemTagManager', function() {
- return $this->getServer()->getSystemTagManager();
- });
-
- $this->registerService('OCP\\SystemTag\\ISystemTagObjectMapper', function() {
- return $this->getServer()->getSystemTagObjectMapper();
- });
-
- $this->registerService('OCP\\IURLGenerator', function($c) {
- return $this->getServer()->getURLGenerator();
- });
-
- $this->registerService('OCP\\IUserManager', function($c) {
- return $this->getServer()->getUserManager();
- });
-
- $this->registerService('OCP\\IUserSession', function($c) {
- return $this->getServer()->getUserSession();
- });
$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
- $this->registerService('OCP\\ISession', function($c) {
- return $this->getServer()->getSession();
- });
-
- $this->registerService('OCP\\Security\\IContentSecurityPolicyManager', function($c) {
- return $this->getServer()->getContentSecurityPolicyManager();
- });
-
- $this->registerService('ServerContainer', function ($c) {
+ $this->registerService(IServerContainer::class, function ($c) {
return $this->getServer();
});
- $this->registerAlias('OCP\\IServerContainer', 'ServerContainer');
+ $this->registerAlias('ServerContainer', IServerContainer::class);
- $this->registerService('Symfony\Component\EventDispatcher\EventDispatcherInterface', function ($c) {
- return $this->getServer()->getEventDispatcher();
- });
-
- $this->registerService('OCP\WorkflowEngine\IManager', function ($c) {
+ $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
return $c->query('OCA\WorkflowEngine\Manager');
});
- $this->registerService('OCP\\AppFramework\\IAppContainer', function ($c) {
+ $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
return $c;
});
- $this->registerService(IMountManager::class, function () {
- return $this->getServer()->getMountManager();
- });
// commonly used attributes
$this->registerService('UserId', function ($c) {
@@ -428,7 +233,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return new CORSMiddleware(
$c['Request'],
$c['ControllerMethodReflector'],
- $c['OCP\IUserSession'],
+ $c->query(IUserSession::class),
$c->getServer()->getBruteForceThrottler()
);
});
@@ -490,7 +295,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
*/
function getServer()
{
- return OC::$server;
+ return $this->server;
}
/**
@@ -569,6 +374,23 @@ class DIContainer extends SimpleContainer implements IAppContainer {
}
public function query($name) {
- return parent::query($name);
+ $name = $this->sanitizeName($name);
+
+ if ($this->offsetExists($name)) {
+ return parent::query($name);
+ } else {
+ if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
+ $segments = explode('\\', $name);
+ if (strtolower($segments[1]) === strtolower($this['AppName'])) {
+ return parent::query($name);
+ }
+ } else if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
+ return parent::query($name);
+ } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
+ return parent::query($name);
+ }
+ }
+
+ return $this->getServer()->query($name);
}
}