Use default value instead of throwing when the service could not be found
This commit is contained in:
parent
1944d9b3ab
commit
d9063b6141
1 changed files with 10 additions and 1 deletions
|
@ -62,7 +62,16 @@ class SimpleContainer extends Container implements IContainer {
|
||||||
$resolveName = $parameterClass->name;
|
$resolveName = $parameterClass->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parameters[] = $this->query($resolveName);
|
try {
|
||||||
|
$parameters[] = $this->query($resolveName);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Service not found, use the default value when available
|
||||||
|
if ($parameter->isDefaultValueAvailable()) {
|
||||||
|
$parameters[] = $parameter->getDefaultValue();
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $class->newInstanceArgs($parameters);
|
return $class->newInstanceArgs($parameters);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue