Skip to content

Commit

Permalink
[DependencyInjection] Fail when dumping a Definition with no class no…
Browse files Browse the repository at this point in the history
…r factory
  • Loading branch information
nicolas-grekas committed Jun 28, 2015
1 parent 1871615 commit 23ad4ad
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Expand Up @@ -1210,11 +1210,6 @@ private function dumpValue($value, $interpolate = true)
foreach ($value->getArguments() as $argument) {
$arguments[] = $this->dumpValue($argument);
}
$class = $this->dumpValue($value->getClass());

if (false !== strpos($class, '$')) {
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
}

if (null !== $value->getFactoryMethod()) {
if (null !== $value->getFactoryClass()) {
Expand All @@ -1228,6 +1223,15 @@ private function dumpValue($value, $interpolate = true)
}
}

$class = $value->getClass();
if (null === $class) {
throw new RuntimeException('Cannot dump definitions which have no class nor factory.');
}
$class = $this->dumpValue($class);
if (false !== strpos($class, '$')) {
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
}

return sprintf('new \\%s(%s)', substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
} elseif ($value instanceof Variable) {
return '$'.$value;
Expand Down

0 comments on commit 23ad4ad

Please sign in to comment.