diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2017-03-19 23:14:47 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-03-21 08:52:20 +0100 |
commit | 21641302a97815c2779f65ffd9efc95cf314e48d (patch) | |
tree | 2a963b50b2f9220c58882192405e660b02d7d104 /lib | |
parent | 7cece61ff66df60e2df258285049b6009e921197 (diff) | |
download | nextcloud-server-21641302a97815c2779f65ffd9efc95cf314e48d.tar.gz nextcloud-server-21641302a97815c2779f65ffd9efc95cf314e48d.zip |
Add DI intergration tests
* Moved some interface definitions to Server.php (more to come)
* Build/Query only for existing classes in the AppContainer
* Build/Query only for classes of the App in the AppContainer
* Offload other stuff to the servercontainer
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/AppFramework/DependencyInjection/DIContainer.php | 16 | ||||
-rw-r--r-- | lib/private/Server.php | 9 |
2 files changed, 16 insertions, 9 deletions
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 939e45dcd35..3bfc64e85b5 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -45,6 +45,7 @@ use OC\AppFramework\Middleware\SessionMiddleware; use OC\AppFramework\Utility\SimpleContainer; use OC\Core\Middleware\TwoFactorMiddleware; use OC\RichObjectStrings\Validator; +use OC\ServerContainer; use OCP\AppFramework\IApi; use OCP\AppFramework\IAppContainer; use OCP\AppFramework\QueryException; @@ -62,24 +63,25 @@ class DIContainer extends SimpleContainer implements IAppContainer { */ private $middleWares = array(); - /** @var IServerContainer */ + /** @var ServerContainer */ private $server; /** * Put your class dependencies in here * @param string $appName the name of the app * @param array $urlParams - * @param IServerContainer $server + * @param ServerContainer $server */ - public function __construct($appName, $urlParams = array(), IServerContainer $server = null){ + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ parent::__construct(); $this['AppName'] = $appName; $this['urlParams'] = $urlParams; /** @var \OC\ServerContainer $server */ if ($server === null) { - $this->server = \OC::$server; + $server = \OC::$server; } + $this->server = $server; $this->server->registerAppContainer($appName, $this); // aliases @@ -570,13 +572,13 @@ class DIContainer extends SimpleContainer implements IAppContainer { public function query($name) { $name = $this->sanitizeName($name); - try { + if ($this->offsetExists($name)) { return parent::query($name); - } catch (QueryException $e) { + } else { if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { $segments = explode('\\', $name); if (strtolower($segments[1]) === strtolower($this['AppName'])) { - throw new QueryException(); + return parent::query($name); } } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 57cc93f4477..8aaecf1d256 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -93,6 +93,7 @@ use OC\Tagging\TagMapper; use OCA\Theming\ThemingDefaults; use OCP\Federation\ICloudIdManager; use OCP\Authentication\LoginCredentials\IStore; +use OCP\IDBConnection; use OCP\IL10N; use OCP\IServerContainer; use OCP\RichObjectStrings\IValidator; @@ -485,7 +486,7 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('CredentialsManager', function (Server $c) { return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); }); - $this->registerService('DatabaseConnection', function (Server $c) { + $this->registerService(IDBConnection::class, function (Server $c) { $systemConfig = $c->getSystemConfig(); $factory = new \OC\DB\ConnectionFactory($systemConfig); $type = $systemConfig->getValue('dbtype', 'sqlite'); @@ -497,6 +498,7 @@ class Server extends ServerContainer implements IServerContainer { $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); return $connection; }); + $this->registerAlias('DatabaseConnection', IDBConnection::class); $this->registerService('HTTPHelper', function (Server $c) { $config = $c->getConfig(); return new HTTPHelper( @@ -740,9 +742,12 @@ class Server extends ServerContainer implements IServerContainer { } return new \OC_Defaults(); }); - $this->registerService('EventDispatcher', function () { + $this->registerService(EventDispatcher::class, function () { return new EventDispatcher(); }); + $this->registerAlias('EventDispatcher', EventDispatcher::class); + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); + $this->registerService('CryptoWrapper', function (Server $c) { // FIXME: Instantiiated here due to cyclic dependency $request = new Request( |