]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't do a recursive search
authorJoas Schilling <coding@schilljs.com>
Wed, 22 Mar 2017 09:33:30 +0000 (10:33 +0100)
committerJoas Schilling <coding@schilljs.com>
Wed, 22 Mar 2017 09:44:13 +0000 (10:44 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/AppFramework/DependencyInjection/DIContainer.php
lib/private/ServerContainer.php
lib/public/IContainer.php
tests/lib/Authentication/TwoFactorAuth/ManagerTest.php

index 9078baf1d2fd0472283f021bb7362bef181b0784..4fb13b09ae0647f472e3a1d98ec0b6e45a0364c5 100644 (file)
@@ -49,6 +49,7 @@ use OC\ServerContainer;
 use OCP\AppFramework\Http\IOutput;
 use OCP\AppFramework\IApi;
 use OCP\AppFramework\IAppContainer;
+use OCP\AppFramework\QueryException;
 use OCP\Files\Folder;
 use OCP\Files\IAppData;
 use OCP\IL10N;
@@ -373,7 +374,25 @@ class DIContainer extends SimpleContainer implements IAppContainer {
                });
        }
 
+       /**
+        * @param string $name
+        * @return mixed
+        * @throws QueryException if the query could not be resolved
+        */
        public function query($name) {
+               try {
+                       return $this->queryNoFallback($name);
+               } catch (QueryException $e) {
+                       return $this->getServer()->query($name);
+               }
+       }
+
+       /**
+        * @param string $name
+        * @return mixed
+        * @throws QueryException if the query could not be resolved
+        */
+       public function queryNoFallback($name) {
                $name = $this->sanitizeName($name);
 
                if ($this->offsetExists($name)) {
@@ -388,6 +407,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
                        }
                }
 
-               return $this->getServer()->query($name);
+               throw new QueryException('Could not resolve ' . $name . '!' .
+                       ' Class can not be instantiated');
        }
 }
index df0293addf75969e001a9da4b6f47d7e23e69cb9..fe868867b5ac96e5b799892759eb146c01d4b3b3 100644 (file)
@@ -79,7 +79,7 @@ class ServerContainer extends SimpleContainer {
                        $segments = explode('\\', $name);
                        $appContainer = $this->getAppContainer(strtolower($segments[1]));
                        try {
-                               return $appContainer->query($name);
+                               return $appContainer->queryNoFallback($name);
                        } catch (QueryException $e) {
                                // Didn't find the service in the respective app container,
                                // ignore it and fall back to the core container.
index 9dc7f9f941e72c17b2a34b6007d49a2714a86659..f7ca0697671c337931da7fef3575737bb201bd25 100644 (file)
@@ -62,6 +62,7 @@ interface IContainer {
         *
         * @param string $name
         * @return mixed
+        * @throws QueryException if the query could not be resolved
         * @since 6.0.0
         */
        public function query($name);
index 1ea17f5d3077a1679048f91ead86a8423130acfc..c031c39b5f28a72c1bb76cc67c64147d5baac411 100644 (file)
@@ -68,7 +68,7 @@ class ManagerTest extends TestCase {
                parent::setUp();
 
                $this->user = $this->createMock(IUser::class);
-               $this->appManager = $this->createMock('\OC\App\AppManager');
+               $this->appManager = $this->createMock(AppManager::class);
                $this->session = $this->createMock(ISession::class);
                $this->config = $this->createMock(IConfig::class);
                $this->activityManager = $this->createMock(IManager::class);