diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index b5bcbdaeb6f..11fed251e66 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -119,26 +119,22 @@ class ServerContainer extends SimpleContainer { * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get */ public function query(string $name, bool $autoload = true) { + // short circuit if have a registered instance ourselves + if (isset($this[$name])) { + return $this[$name]; + } $name = $this->sanitizeName($name); - if (str_starts_with($name, 'OCA\\')) { - // Skip server container query for app namespace classes + // In case the service starts with OCA\ we try to find the service in + // the apps container first. + if (($appContainer = $this->getAppContainerForService($name)) !== null) { try { - return parent::query($name, false); + return $appContainer->queryNoFallback($name); } catch (QueryException $e) { - // Continue with general autoloading then - } - // In case the service starts with OCA\ we try to find the service in - // the apps container first. - if (($appContainer = $this->getAppContainerForService($name)) !== null) { - try { - return $appContainer->queryNoFallback($name); - } catch (QueryException $e) { - // Didn't find the service or the respective app container - // In this case the service won't be part of the core container, - // so we can throw directly - throw $e; - } + // Didn't find the service or the respective app container + // In this case the service won't be part of the core container, + // so we can throw directly + throw $e; } } elseif (str_starts_with($name, 'OC\\Settings\\') && substr_count($name, '\\') >= 3) { $segments = explode('\\', $name);