From 5695a4ec9287775912b9df1b0038964543e257d1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 22 Mar 2017 10:33:30 +0100 Subject: [PATCH] Don't do a recursive search Signed-off-by: Joas Schilling --- .../DependencyInjection/DIContainer.php | 22 ++++++++++++++++++- lib/private/ServerContainer.php | 2 +- lib/public/IContainer.php | 1 + .../TwoFactorAuth/ManagerTest.php | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 9078baf1d2..4fb13b09ae 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -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'); } } diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index df0293addf..fe868867b5 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -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. diff --git a/lib/public/IContainer.php b/lib/public/IContainer.php index 9dc7f9f941..f7ca069767 100644 --- a/lib/public/IContainer.php +++ b/lib/public/IContainer.php @@ -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); diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index 1ea17f5d30..c031c39b5f 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -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);