diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/AppFramework/DependencyInjection/DIContainer.php | 9 | ||||
-rw-r--r-- | lib/private/AppFramework/Utility/SimpleContainer.php | 14 | ||||
-rw-r--r-- | lib/private/ServerContainer.php | 9 | ||||
-rw-r--r-- | lib/public/IContainer.php | 3 |
4 files changed, 11 insertions, 24 deletions
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index a6a9b205747..6d337bb9327 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -374,17 +374,12 @@ class DIContainer extends SimpleContainer implements IAppContainer { }); } - /** - * @param string $name - * @return mixed - * @throws QueryException if the query could not be resolved - */ - public function query($name) { + public function query(string $name, bool $autoload = true) { try { return $this->queryNoFallback($name); } catch (QueryException $firstException) { try { - return $this->getServer()->query($name); + return $this->getServer()->query($name, $autoload); } catch (QueryException $secondException) { if ($firstException->getCode() === 1) { throw $secondException; diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index 6c2844e681b..6f50523bbf6 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -65,7 +65,8 @@ class SimpleContainer extends Container implements IContainer { } try { - $parameters[] = $this->query($resolveName); + $builtIn = $parameter->hasType() && $parameter->getType()->isBuiltin(); + $parameters[] = $this->query($resolveName, !$builtIn); } catch (QueryException $e) { // Service not found, use the default value when available if ($parameter->isDefaultValueAvailable()) { @@ -105,23 +106,18 @@ class SimpleContainer extends Container implements IContainer { } } - - /** - * @param string $name name of the service to query for - * @return mixed registered service for the given $name - * @throws QueryException if the query could not be resolved - */ - public function query($name) { + public function query(string $name, bool $autoload = true) { $name = $this->sanitizeName($name); if ($this->offsetExists($name)) { return $this->offsetGet($name); - } else { + } else if ($autoload) { $object = $this->resolve($name); $this->registerService($name, function () use ($object) { return $object; }); return $object; } + throw new QueryException('Could not resolve ' . $name . '!'); } /** diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 8c2b49bb085..b67b4d1e701 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -113,12 +113,7 @@ class ServerContainer extends SimpleContainer { throw new QueryException(); } - /** - * @param string $name name of the service to query for - * @return mixed registered service for the given $name - * @throws QueryException if the query could not be resolved - */ - public function query($name) { + public function query(string $name, bool $autoload = true) { $name = $this->sanitizeName($name); if (isset($this[$name])) { @@ -147,6 +142,6 @@ class ServerContainer extends SimpleContainer { } } - return parent::query($name); + return parent::query($name, $autoload); } } diff --git a/lib/public/IContainer.php b/lib/public/IContainer.php index f7ca0697671..558c72291c5 100644 --- a/lib/public/IContainer.php +++ b/lib/public/IContainer.php @@ -61,11 +61,12 @@ interface IContainer { * Look up a service for a given name in the container. * * @param string $name + * @param bool $autoload Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example * @return mixed * @throws QueryException if the query could not be resolved * @since 6.0.0 */ - public function query($name); + public function query(string $name, bool $autoload = true); /** * A value is stored in the container with it's corresponding name |