[DI] fix dumping errored definitions

This commit is contained in:
Nicolas Grekas 2020-03-04 16:44:30 +01:00
parent 4103a6ebd2
commit 8179928336
2 changed files with 24 additions and 13 deletions

View File

@ -794,21 +794,27 @@ EOF;
EOF;
}
$this->serviceCalls = [];
$this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls);
if ($definition->hasErrors() && $e = $definition->getErrors()) {
$this->addThrow = true;
if ($definition->isDeprecated()) {
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
$code .= sprintf(" \$this->throw(%s);\n", $this->export(reset($e)));
} else {
$this->serviceCalls = [];
$this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls);
if ($definition->isDeprecated()) {
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
}
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
$factoryCode = $asFile ? ($definition->isShared() ? "\$this->load('%s.php', false)" : '$this->factories[%2$s](false)') : '$this->%s(false)';
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName, $this->doExport($id)));
}
$code .= $this->addServiceInclude($id, $definition);
$code .= $this->addInlineService($id, $definition);
}
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
$factoryCode = $asFile ? ($definition->isShared() ? "\$this->load('%s.php', false)" : '$this->factories[%2$s](false)') : '$this->%s(false)';
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName, $this->doExport($id)));
}
$code .= $this->addServiceInclude($id, $definition);
$code .= $this->addInlineService($id, $definition);
if ($asFile) {
$code = implode("\n", array_map(function ($line) { return $line ? substr($line, 8) : $line; }, explode("\n", $code)));
} else {

View File

@ -120,6 +120,11 @@ class Symfony_DI_PhpDumper_Service_Locator_Argument extends Container
*/
protected function getFoo4Service()
{
return $this->privates['foo4'] = new \stdClass();
$this->throw('BOOM');
}
protected function throw($message)
{
throw new RuntimeException($message);
}
}