Skip to content

Commit 1992c3b

Browse files
committed
[DependencyInjection] fixes a bug which might have occurred when using property injection under certain circumstances
1 parent 75ac0f5 commit 1992c3b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public function formatInlineService(CompilerPassInterface $pass, $id, $target)
2121
return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target));
2222
}
2323

24+
public function formatUpdateReference(CompilerPassInterface $pass, $serviceId, $oldDestId, $newDestId)
25+
{
26+
return $this->format($pass, sprintf('Changed reference of service "%s" previously pointing to "%s" to "%s".', $serviceId, $oldDestId, $newDestId));
27+
}
28+
2429
public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId)
2530
{
2631
return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId));

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@
2222
*/
2323
class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
2424
{
25+
private $compiler;
26+
private $formatter;
27+
private $sourceId;
28+
2529
/**
2630
* Process the Container to replace aliases with service definitions.
2731
*
28-
* @param ContainerBuilder $container
32+
* @param ContainerBuilder $container
2933
*/
3034
public function process(ContainerBuilder $container)
3135
{
36+
$this->compiler = $container->getCompiler();
37+
$this->formatter = $this->compiler->getLoggingFormatter();
38+
3239
foreach ($container->getAliases() as $id => $alias) {
3340
$aliasId = (string) $alias;
3441

@@ -67,14 +74,20 @@ private function updateReferences($container, $currentId, $newId)
6774
}
6875
}
6976

70-
foreach ($container->getDefinitions() as $definition) {
77+
foreach ($container->getDefinitions() as $id => $definition) {
78+
$this->sourceId = $id;
79+
7180
$definition->setArguments(
7281
$this->updateArgumentReferences($definition->getArguments(), $currentId, $newId)
7382
);
7483

7584
$definition->setMethodCalls(
7685
$this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId)
7786
);
87+
88+
$definition->setProperties(
89+
$this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
90+
);
7891
}
7992
}
8093

@@ -93,6 +106,7 @@ private function updateArgumentReferences(array $arguments, $currentId, $newId)
93106
} else if ($argument instanceof Reference) {
94107
if ($currentId === (string) $argument) {
95108
$arguments[$k] = new Reference($newId, $argument->getInvalidBehavior());
109+
$this->compiler->addLogMessage($this->formatter->formatUpdateReference($this, $this->sourceId, $currentId, $newId));
96110
}
97111
}
98112
}

0 commit comments

Comments
 (0)