remove duplicate OCA query handling and add earlier short cirtcuit for when instances are already created

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2023-02-08 16:22:55 +01:00
parent 8f4a19ccab
commit 3f487633d5
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB

View file

@ -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);