Avoid duplicate App container creation

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-03-05 17:55:35 +01:00
parent a4b34abe45
commit c5ab74348c
No known key found for this signature in database
GPG key ID: 7076EA9751AACDDA
2 changed files with 19 additions and 1 deletions

View file

@ -71,6 +71,19 @@ class ServerContainer extends SimpleContainer {
$this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container;
}
/**
* @param string $appName
* @return DIContainer
* @throws QueryException
*/
public function getRegisteredAppContainer(string $appName) {
if (isset($this->appContainers[strtolower(App::buildAppNamespace($appName, ''))])) {
return $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))];
}
throw new QueryException();
}
/**
* @param string $namespace
* @param string $sensitiveNamespace

View file

@ -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);
}
}
/**