bug #15083 [DependencyInjection] Fail when dumping a Definition with no class nor factory (nicolas-grekas)
This PR was merged into the 2.3 branch.
Discussion
----------
[DependencyInjection] Fail when dumping a Definition with no class nor factory
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
I tried creating an anonymous inline service with a DefinitionDecorator, but that did not work.
Here is the fix.
Commits
-------
23ad4ad
[DependencyInjection] Fail when dumping a Definition with no class nor factory
This commit is contained in:
commit
e93a3d7896
|
@ -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;
|
||||
|
|
Reference in New Issue