diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index f03bcda92248b..74135c055ca95 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -308,28 +308,12 @@ public function has($id): bool { * @param list $chain */ #[\Override] - protected function query(string $name, bool $autoload = true, array $chain = []): mixed { + protected function query(string $name, bool $autoload = true, array $chain = [], bool $fallback = true): mixed { $name = $this->resolveAlias($name); if ($name === 'AppName' || $name === 'appName') { return $this->appName; } - $result = $this->queryNoFallback($name, $chain); - if ($result !== null) { - return $result; - } - return $this->server->query($name, $autoload, $chain); - } - - /** - * @param string already sanitized $name - * @param list $chain - * @return mixed - * @throws QueryException if the query could not be resolved - * @internal - */ - public function queryNoFallback($name, array $chain) { - $name = $this->resolveAlias($name); if (isset($this->container[$name])) { return $this->container[$name]; } elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) { @@ -343,6 +327,10 @@ public function queryNoFallback($name, array $chain) { /* AppFramework services are scoped to the application */ return parent::query($name, chain: $chain); } - return null; + if ($fallback) { + return $this->server->query($name, $autoload, $chain); + } else { + throw new QueryException('Could not resolve ' . $name . '! Class can not be instantiated', 1); + } } } diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 0261e2996f4cd..f3a49229770a6 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -124,16 +124,9 @@ public function has($id, bool $noRecursion = false): bool { #[\Override] protected function query(string $name, bool $autoload = true, array $chain = []): mixed { $name = $this->resolveAlias($name); - if (str_starts_with($name, 'OCA\\')) { - // In case the service starts with OCA\ we try to find the service in the apps container. - if (($appContainer = $this->getAppContainerForService($name)) !== null) { - $result = $appContainer->queryNoFallback($name, $chain); - if ($result !== null) { - return $result; - } - throw new QueryException('Could not resolve ' . $name . '!' - . ' Class can not be instantiated', 1); - } + // In case the service starts with OCA\ we try to find the service in the apps container. + if (($appContainer = $this->getAppContainerForService($name)) !== null) { + return $appContainer->query($name, $autoload, $chain, fallback:false); } return parent::query($name, $autoload, $chain);