diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-05-19 16:18:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-19 16:18:31 +0200 |
commit | 32558991a6f2e6bca0f4e8a6a05688341584f7ee (patch) | |
tree | 743978b81e1d8f8bb26b9fe189b8daadcaf7422a /lib | |
parent | 90837b9175022dbbd72281a87eda6314e1df3a70 (diff) | |
parent | aa831276864754e6ddc7a999b43c8c3683607a9e (diff) | |
download | nextcloud-server-32558991a6f2e6bca0f4e8a6a05688341584f7ee.tar.gz nextcloud-server-32558991a6f2e6bca0f4e8a6a05688341584f7ee.zip |
Merge pull request #4962 from nextcloud/backport-4905
Allow automatic DI for apps that don't register the container in app.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/ServerContainer.php | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 3391dd83a04..97a3b99d534 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -38,6 +38,9 @@ class ServerContainer extends SimpleContainer { protected $appContainers; /** @var string[] */ + protected $hasNoAppContainer; + + /** @var string[] */ protected $namespaces; /** @@ -47,6 +50,7 @@ class ServerContainer extends SimpleContainer { parent::__construct(); $this->appContainers = []; $this->namespaces = []; + $this->hasNoAppContainer = []; } /** @@ -69,15 +73,27 @@ class ServerContainer extends SimpleContainer { /** * @param string $namespace + * @param string $sensitiveNamespace * @return DIContainer * @throws QueryException */ - protected function getAppContainer($namespace) { + protected function getAppContainer($namespace, $sensitiveNamespace) { if (isset($this->appContainers[$namespace])) { return $this->appContainers[$namespace]; } if (isset($this->namespaces[$namespace])) { + if (!isset($this->hasNoAppContainer[$namespace])) { + $applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application'; + if (class_exists($applicationClassName)) { + new $applicationClassName(); + if (isset($this->appContainers[$namespace])) { + return $this->appContainers[$namespace]; + } + } + $this->hasNoAppContainer[$namespace] = true; + } + return new DIContainer($this->namespaces[$namespace]); } throw new QueryException(); @@ -96,7 +112,7 @@ class ServerContainer extends SimpleContainer { if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { $segments = explode('\\', $name); try { - $appContainer = $this->getAppContainer(strtolower($segments[1])); + $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); return $appContainer->queryNoFallback($name); } catch (QueryException $e) { // Didn't find the service or the respective app container, |