diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-11-03 11:53:43 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-11-03 11:53:43 +0100 |
commit | 78842348b281a02374fd21ba12644e2a1bb5a99d (patch) | |
tree | 34cfe503e36a0222c2df58f0b9a7af69cb3836dd /lib/private/AppFramework | |
parent | ba93afbddd4930408129e863957fd7b631582ae2 (diff) | |
download | nextcloud-server-78842348b281a02374fd21ba12644e2a1bb5a99d.tar.gz nextcloud-server-78842348b281a02374fd21ba12644e2a1bb5a99d.zip |
feat(dependencyinjection): Allow optional (nullable) services
Allows working with classes that might or might not be available.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r-- | lib/private/AppFramework/Utility/SimpleContainer.php | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index 7aa5cb83926..ecd8485cd7b 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -105,6 +105,11 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { try { return $this->query($resolveName); } catch (QueryException $e2) { + // Pass null if typed and nullable + if ($parameter->allowsNull() && ($parameterType instanceof ReflectionNamedType)) { + return null; + } + // don't lose the error we got while trying to query by type throw new QueryException($e->getMessage(), (int) $e->getCode(), $e); } |