From 23ad4ad133a944fd1921a8b1a9ddcdd92c8e97e2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 24 Jun 2015 10:29:42 +0200 Subject: [PATCH] [DependencyInjection] Fail when dumping a Definition with no class nor factory --- .../DependencyInjection/Dumper/PhpDumper.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index fd82e6df91..64d5fb9bb6 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1210,11 +1210,6 @@ EOF; 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()) { @@ -1228,6 +1223,15 @@ EOF; } } + $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;