]> source.dussan.org Git - nextcloud-server.git/commitdiff
Register the namespace with the autoloading to allow reverse recovery 3977/head
authorJoas Schilling <coding@schilljs.com>
Wed, 22 Mar 2017 10:50:58 +0000 (11:50 +0100)
committerJoas Schilling <coding@schilljs.com>
Wed, 22 Mar 2017 10:55:04 +0000 (11:55 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/ServerContainer.php
lib/private/legacy/app.php

index fe868867b5ac96e5b799892759eb146c01d4b3b3..e7b1ed2dad71d75edaba02d2ffc235788680c9ad 100644 (file)
@@ -37,12 +37,26 @@ class ServerContainer extends SimpleContainer {
        /** @var DIContainer[] */
        protected $appContainers;
 
+       /** @var string[] */
+       protected $namespaces;
+
        /**
         * ServerContainer constructor.
         */
        public function __construct() {
                parent::__construct();
                $this->appContainers = [];
+               $this->namespaces = [];
+       }
+
+       /**
+        * @param string $appName
+        * @param string $appNamespace
+        */
+       public function registerNamespace($appName, $appNamespace) {
+               // Cut of OCA\ and lowercase
+               $appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1));
+               $this->namespaces[$appNamespace] = $appName;
        }
 
        /**
@@ -54,15 +68,19 @@ class ServerContainer extends SimpleContainer {
        }
 
        /**
-        * @param string $appName
+        * @param string $namespace
         * @return DIContainer
+        * @throws QueryException
         */
-       public function getAppContainer($appName) {
-               if (isset($this->appContainers[$appName])) {
-                       return $this->appContainers[$appName];
+       protected function getAppContainer($namespace) {
+               if (isset($this->appContainers[$namespace])) {
+                       return $this->appContainers[$namespace];
                }
 
-               return new DIContainer($appName);
+               if (isset($this->namespaces[$namespace])) {
+                       return new DIContainer($this->namespaces[$namespace]);
+               }
+               throw new QueryException();
        }
 
        /**
@@ -77,11 +95,11 @@ class ServerContainer extends SimpleContainer {
                // the apps container first.
                if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
                        $segments = explode('\\', $name);
-                       $appContainer = $this->getAppContainer(strtolower($segments[1]));
                        try {
+                               $appContainer = $this->getAppContainer(strtolower($segments[1]));
                                return $appContainer->queryNoFallback($name);
                        } catch (QueryException $e) {
-                               // Didn't find the service in the respective app container,
+                               // Didn't find the service or the respective app container,
                                // ignore it and fall back to the core container.
                        }
                }
index c82d620882d81f03cfc79467c5d9989b3edfb84f..5343e7ad17220d83a5be663f2f83bfae980656bd 100644 (file)
@@ -189,6 +189,7 @@ class OC_App {
                self::$alreadyRegistered[$key] = true;
                // Register on PSR-4 composer autoloader
                $appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
+               \OC::$server->registerNamespace($app, $appNamespace);
                \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
                if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
                        \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);