8000 [DependencyInjection] Fix serialization of \Closure in RemoveUnusedDe… · symfony/symfony@b092502 · GitHub
[go: up one dir, main page]

Skip to content

Commit b092502

Browse files
author
Anthony MARTIN
committed
[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
1 parent 9429fac commit b092502

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function process(ContainerBuilder $container)
7070
foreach ($container->getDefinitions() as $id => $definition) {
7171
if (!isset($connectedIds[$id])) {
7272
$container->removeDefinition($id);
73-
$container->resolveEnvPlaceholders(serialize($definition));
73+
$container->resolveEnvPlaceholders(!$definition->hasErrors() ? serialize($definition) : $definition);
7474
$container->log($this, sprintf('Removed service "%s"; reason: unused.', $id));
7575
}
7676
}

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,10 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
13941394
$value = $bag->resolveValue($value);
13951395
}
13961396

1397+
if ($value instanceof Definition) {
1398+
$value = (array) $value;
1399+
}
1400+
13971401
if (\is_array($value)) {
13981402
$result = [];
13991403
foreach ($value as $k => $v) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ public function testProcessDoesNotErrorOnServicesThatDoNotHaveDefinitions()
142142
$this->assertFalse($container->hasDefinition('not.defined'));
143143
}
144144

145+
public function testProcessWorksWithClosureErrorsInDefinitions()
146+
{
147+
$definition = new Definition();
148+
$definition->addError(function () {
149+
return 'foo bar';
150+
});
151+
152+
$container = new ContainerBuilder();
153+
$container
154+
->setDefinition('foo', $definition)
155+
->setPublic(false)
156+
;
157+
158+
$this->process($container);
159+
160+
$this->assertFalse($container->hasDefinition('foo'));
161+
}
162+
145163
protected function process(ContainerBuilder $container)
146164
{
147165
(new RemoveUnusedDefinitionsPass())->process($container);

0 commit comments

Comments
 (0)
0