[DependencyInjection] Fix serialization of \Closure in RemoveUnusedDefinitionsPass
Signed-off-by: Anthony MARTIN <anthony.martin@sensiolabs.com> | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29694 | License | MIT | Doc PR | n/a Fix the issue #29694
This commit is contained in:
parent
9429face97
commit
b0925025f8
@ -70,7 +70,7 @@ class RemoveUnusedDefinitionsPass extends AbstractRecursivePass implements Repea
|
|||||||
foreach ($container->getDefinitions() as $id => $definition) {
|
foreach ($container->getDefinitions() as $id => $definition) {
|
||||||
if (!isset($connectedIds[$id])) {
|
if (!isset($connectedIds[$id])) {
|
||||||
$container->removeDefinition($id);
|
$container->removeDefinition($id);
|
||||||
$container->resolveEnvPlaceholders(serialize($definition));
|
$container->resolveEnvPlaceholders(!$definition->hasErrors() ? serialize($definition) : $definition);
|
||||||
$container->log($this, sprintf('Removed service "%s"; reason: unused.', $id));
|
$container->log($this, sprintf('Removed service "%s"; reason: unused.', $id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1394,6 +1394,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
$value = $bag->resolveValue($value);
|
$value = $bag->resolveValue($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($value instanceof Definition) {
|
||||||
|
$value = (array) $value;
|
||||||
|
}
|
||||||
|
|
||||||
if (\is_array($value)) {
|
if (\is_array($value)) {
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
|
@ -142,6 +142,24 @@ class RemoveUnusedDefinitionsPassTest extends TestCase
|
|||||||
$this->assertFalse($container->hasDefinition('not.defined'));
|
$this->assertFalse($container->hasDefinition('not.defined'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProcessWorksWithClosureErrorsInDefinitions()
|
||||||
|
{
|
||||||
|
$definition = new Definition();
|
||||||
|
$definition->addError(function () {
|
||||||
|
return 'foo bar';
|
||||||
|
});
|
||||||
|
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container
|
||||||
|
->setDefinition('foo', $definition)
|
||||||
|
->setPublic(false)
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->process($container);
|
||||||
|
|
||||||
|
$this->assertFalse($container->hasDefinition('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
protected function process(ContainerBuilder $container)
|
protected function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
(new RemoveUnusedDefinitionsPass())->process($container);
|
(new RemoveUnusedDefinitionsPass())->process($container);
|
||||||
|
Reference in New Issue
Block a user