Matthias Lantsch(2 years, 1 month ago)
Allow for catching type errors when injecting dependencies
Browse Filesdiff --git a/72fa9456440f9ab849554b8370a8c2f1fba63060 b/f5ab88d99298c9bfe67415b50c10a2711c35d2de
index 72fa945..f5ab88d 100644
--- a/72fa9456440f9ab849554b8370a8c2f1fba63060
+++ b/f5ab88d99298c9bfe67415b50c10a2711c35d2de
@@ -88,9 +88,14 @@ class Container implements ContainerInterface {
if (mb_strpos($propertyName, self::DI_PREFIX) === 0) {
$depKey = str_replace(self::DI_PREFIX, '', $propertyName);
if (!$this->has($depKey) && $forceInjection) {
- throw new DependencyNotFoundException("Dependency '{$depKey}' does not exist on Dependency Container");
+ try {
+ $dependencyUser->{$propertyName} = null;
+ } catch (TypeError $e) {
+ throw new DependencyNotFoundException("Dependency '{$depKey}' does not exist on Dependency Container");
+ }
+ } else {
+ $dependencyUser->{$propertyName} = $this->get($depKey, $injectFor);
}
- $dependencyUser->{$propertyName} = $this->get($depKey, $injectFor);
}
}
}