Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private function addServiceInlinedDefinitions($id, $definition)
throw new ServiceCircularReferenceException($id, array($id));
}

$code .= $this->addNewInstance($sDefinition, '$'.$name, ' = ');
$code .= $this->addNewInstance($sDefinition, '$'.$name, ' = ', $id);

if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
Expand Down Expand Up @@ -404,7 +404,7 @@ private function addServiceInstance($id, $definition)
$instantiation .= ' = ';
}

$code = $this->addNewInstance($definition, $return, $instantiation);
$code = $this->addNewInstance($definition, $return, $instantiation, $id);

if (!$simple) {
$code .= "\n";
Expand Down Expand Up @@ -692,7 +692,7 @@ private function addServices()
return $publicServices.$privateServices;
}

private function addNewInstance(Definition $definition, $return, $instantiation)
private function addNewInstance(Definition $definition, $return, $instantiation, $id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i realized that the id parameter was removed since symfony 2 (i tested this in my project with symfony 2...)

not sure if its ok to pass the id around just for the purpose of the error message, but without the id the message becomes a lot less useful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a private method so I don't think it really matters that much. For the sake of DX, I'd say it's a good case to pass it along because it's required to build the error message.

{
$class = $this->dumpValue($definition->getClass());

Expand All @@ -716,6 +716,10 @@ private function addNewInstance(Definition $definition, $return, $instantiation)
$class = $this->dumpValue($callable[0]);
// If the class is a string we can optimize call_user_func away
if (strpos($class, "'") === 0) {
if ("''" === $class) {
throw new RuntimeException(sprintf('Cannot dump definition: The "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id));
}

return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '');
}

Expand Down