summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/dav/lib/AppInfo/Application.php2
-rw-r--r--apps/dav/tests/unit/AppInfo/ApplicationTest.php21
-rw-r--r--lib/private/ServerContainer.php20
-rw-r--r--lib/public/AppFramework/App.php7
4 files changed, 26 insertions, 24 deletions
diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php
index a90e42d56f8..41570ee7442 100644
--- a/apps/dav/lib/AppInfo/Application.php
+++ b/apps/dav/lib/AppInfo/Application.php
@@ -77,7 +77,7 @@ class Application extends App {
}
/**
- * @param IManager $contactsManager
+ * @param IContactsManager $contactsManager
*/
public function setupSystemContactsProvider(IContactsManager $contactsManager) {
/** @var ContactsManager $cm */
diff --git a/apps/dav/tests/unit/AppInfo/ApplicationTest.php b/apps/dav/tests/unit/AppInfo/ApplicationTest.php
index d4f53d360a9..d34749ec92b 100644
--- a/apps/dav/tests/unit/AppInfo/ApplicationTest.php
+++ b/apps/dav/tests/unit/AppInfo/ApplicationTest.php
@@ -26,7 +26,6 @@ namespace OCA\DAV\Tests\unit\AppInfo;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\ContactsManager;
-use OCP\Contacts\IManager;
use Test\TestCase;
/**
@@ -43,24 +42,8 @@ class ApplicationTest extends TestCase {
// assert service instances in the container are properly setup
$s = $c->query(ContactsManager::class);
- $this->assertInstanceOf('OCA\DAV\CardDAV\ContactsManager', $s);
+ $this->assertInstanceOf(ContactsManager::class, $s);
$s = $c->query(CardDavBackend::class);
- $this->assertInstanceOf('OCA\DAV\CardDAV\CardDavBackend', $s);
- }
-
- public function testContactsManagerSetup() {
- $app = new Application();
- $c = $app->getContainer();
- $c->registerService(CardDavBackend::class, function() {
- $service = $this->createMock(CardDavBackend::class);
- $service->method('getAddressBooksForUser')->willReturn([]);
- return $service;
- });
-
- // assert setupContactsProvider() is proper
- /** @var IManager|\PHPUnit_Framework_MockObject_MockObject $cm */
- $cm = $this->createMock(IManager::class);
- $app->setupContactsProvider($cm, 'xxx');
- $this->addToAssertionCount(1);
+ $this->assertInstanceOf(CardDavBackend::class, $s);
}
}
diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php
index e1447d2f06b..8c2b49bb085 100644
--- a/lib/private/ServerContainer.php
+++ b/lib/private/ServerContainer.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -57,7 +58,7 @@ class ServerContainer extends SimpleContainer {
* @param string $appName
* @param string $appNamespace
*/
- public function registerNamespace($appName, $appNamespace) {
+ public function registerNamespace(string $appName, string $appNamespace): void {
// Cut of OCA\ and lowercase
$appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1));
$this->namespaces[$appNamespace] = $appName;
@@ -67,17 +68,30 @@ class ServerContainer extends SimpleContainer {
* @param string $appName
* @param DIContainer $container
*/
- public function registerAppContainer($appName, DIContainer $container) {
+ public function registerAppContainer(string $appName, DIContainer $container): void {
$this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container;
}
/**
+ * @param string $appName
+ * @return DIContainer
+ * @throws QueryException
+ */
+ public function getRegisteredAppContainer(string $appName): DIContainer {
+ if (isset($this->appContainers[strtolower(App::buildAppNamespace($appName, ''))])) {
+ return $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))];
+ }
+
+ throw new QueryException();
+ }
+
+ /**
* @param string $namespace
* @param string $sensitiveNamespace
* @return DIContainer
* @throws QueryException
*/
- protected function getAppContainer($namespace, $sensitiveNamespace) {
+ protected function getAppContainer(string $namespace, string $sensitiveNamespace): DIContainer {
if (isset($this->appContainers[$namespace])) {
return $this->appContainers[$namespace];
}
diff --git a/lib/public/AppFramework/App.php b/lib/public/AppFramework/App.php
index b6ed2da5076..06524e4bf02 100644
--- a/lib/public/AppFramework/App.php
+++ b/lib/public/AppFramework/App.php
@@ -66,11 +66,16 @@ class App {
/**
+ * @param string $appName
* @param array $urlParams an array with variables extracted from the routes
* @since 6.0.0
*/
public function __construct(string $appName, array $urlParams = []) {
- $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
+ try {
+ $this->container = \OC::$server->getRegisteredAppContainer($appName);
+ } catch (QueryException $e) {
+ $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
+ }
}
/**