Use default value instead of throwing when the service could not be found

This commit is contained in:
Joas Schilling 2016-09-20 13:26:06 +02:00
parent 1944d9b3ab
commit d9063b6141
No known key found for this signature in database
GPG key ID: E166FD8976B3BAC8

View file

@ -62,7 +62,16 @@ class SimpleContainer extends Container implements IContainer {
$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);
}