Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0999326

Browse files
committed
better error message if factory class is empty
1 parent d479934 commit 0999326

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private function addServiceInlinedDefinitions($id, $definition)
330330
throw new ServiceCircularReferenceException($id, array($id));
331331
}
332332

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

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

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

409409
if (!$simple) {
410410
$code .= "\n";
@@ -692,7 +692,7 @@ private function addServices()
692692
return $publicServices.$privateServices;
693693
}
694694

695-
private function addNewInstance(Definition $definition, $return, $instantiation)
695+
private function addNewInstance(Definition $definition, $return, $instantiation, $id)
696696
{
697697
$class = $this->dumpValue($definition->getClass());
698698

@@ -716,6 +716,10 @@ private function addNewInstance(Definition $definition, $return, $instantiation)
716716
$class = $this->dumpValue($callable[0]);
717717
// If the class is a string we can optimize call_user_func away
718718
if (strpos($class, "'") === 0) {
719+
if ("''" === $class) {
720+
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));
721+
}
722+
719723
return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '');
720724
}
721725

0 commit comments

Comments
 (0)