]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow automatic DI for apps that don't register the container in app.php 4962/head
authorJoas Schilling <coding@schilljs.com>
Tue, 16 May 2017 15:37:41 +0000 (17:37 +0200)
committerJoas Schilling <coding@schilljs.com>
Fri, 19 May 2017 11:49:36 +0000 (13:49 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/ServerContainer.php

index 3391dd83a04096f2803296fed51653d5f1d29b7b..97a3b99d534f3f6e328e176e926b9964d5049062 100644 (file)
@@ -37,6 +37,9 @@ class ServerContainer extends SimpleContainer {
        /** @var DIContainer[] */
        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,