Skip to content
Permalink
Browse files

bug #30048 [DependencyInjection] Fix serialization of \Closure in Rem…

…oveUnusedDefinitionsPass (XuruDragon)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[DependencyInjection] Fix serialization of \Closure in RemoveUnusedDefinitionsPass

| 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

Commits
-------

b092502 [DependencyInjection] Fix serialization of \Closure in RemoveUnusedDefinitionsPass
  • Loading branch information...
nicolas-grekas committed Feb 1, 2019
2 parents 9429fac + b092502 commit bd123e4c36e20d0a11e5ff0605ff129f6c47f3c6
@@ -70,7 +70,7 @@ public function process(ContainerBuilder $container)
foreach ($container->getDefinitions() as $id => $definition) {
if (!isset($connectedIds[$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));
}
}
@@ -1394,6 +1394,10 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
$value = $bag->resolveValue($value);
}
if ($value instanceof Definition) {
$value = (array) $value;
}
if (\is_array($value)) {
$result = [];
foreach ($value as $k => $v) {
@@ -142,6 +142,24 @@ public function testProcessDoesNotErrorOnServicesThatDoNotHaveDefinitions()
$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)
{
(new RemoveUnusedDefinitionsPass())->process($container);

0 comments on commit bd123e4

Please sign in to comment.
You can’t perform that action at this time.