Skip to content

Commit 74f9e79

Browse files
[DI] fix dumping errored definitions
1 parent 9af0bfd commit 74f9e79

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

Dumper/PhpDumper.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -794,20 +794,26 @@ protected function {$methodName}($lazyInitialization)
794794
EOF;
795795
}
796796

797-
$this->serviceCalls = [];
798-
$this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls);
797+
if ($definition->hasErrors() && $e = $definition->getErrors()) {
798+
$this->addThrow = true;
799799

800-
if ($definition->isDeprecated()) {
801-
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
802-
}
800+
$code .= sprintf(" \$this->throw(%s);\n", $this->export(reset($e)));
801+
} else {
802+
$this->serviceCalls = [];
803+
$this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls);
803804

804-
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
805-
$factoryCode = $asFile ? ($definition->isShared() ? "\$this->load('%s.php', false)" : '$this->factories[%2$s](false)') : '$this->%s(false)';
806-
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName, $this->doExport($id)));
807-
}
805+
if ($definition->isDeprecated()) {
806+
$code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
807+
}
808808

809-
$code .= $this->addServiceInclude($id, $definition);
810-
$code .= $this->addInlineService($id, $definition);
809+
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
810+
$factoryCode = $asFile ? ($definition->isShared() ? "\$this->load('%s.php', false)" : '$this->factories[%2$s](false)') : '$this->%s(false)';
811+
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName, $this->doExport($id)));
812+
}
813+
814+
$code .= $this->addServiceInclude($id, $definition);
815+
$code .= $this->addInlineService($id, $definition);
816+
}
811817

812818
if ($asFile) {
813819
$code = implode("\n", array_map(function ($line) { return $line ? substr($line, 8) : $line; }, explode("\n", $code)));

Tests/Fixtures/php/services_service_locator_argument.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ protected function getFoo3Service()
120120
*/
121121
protected function getFoo4Service()
122122
{
123-
return $this->privates['foo4'] = new \stdClass();
123+
$this->throw('BOOM');
124+
}
125+
126+
protected function throw($message)
127+
{
128+
throw new RuntimeException($message);
124129
}
125130
}

0 commit comments

Comments
 (0)