Skip to content

Commit

Permalink
[DependencyInjection] fixes a bug which might have occurred when usin…
Browse files Browse the repository at this point in the history
…g property injection under certain circumstances
  • Loading branch information
schmittjoh committed Apr 14, 2011
1 parent 75ac0f5 commit 1992c3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Expand Up @@ -21,6 +21,11 @@ public function formatInlineService(CompilerPassInterface $pass, $id, $target)
return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target));
}

public function formatUpdateReference(CompilerPassInterface $pass, $serviceId, $oldDestId, $newDestId)
{
return $this->format($pass, sprintf('Changed reference of service "%s" previously pointing to "%s" to "%s".', $serviceId, $oldDestId, $newDestId));
}

public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId)
{
return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId));
Expand Down
Expand Up @@ -22,13 +22,20 @@
*/
class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
{
private $compiler;
private $formatter;
private $sourceId;

/**
* Process the Container to replace aliases with service definitions.
*
* @param ContainerBuilder $container
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->compiler = $container->getCompiler();
$this->formatter = $this->compiler->getLoggingFormatter();

foreach ($container->getAliases() as $id => $alias) {
$aliasId = (string) $alias;

Expand Down Expand Up @@ -67,14 +74,20 @@ private function updateReferences($container, $currentId, $newId)
}
}

foreach ($container->getDefinitions() as $definition) {
foreach ($container->getDefinitions() as $id => $definition) {
$this->sourceId = $id;

$definition->setArguments(
$this->updateArgumentReferences($definition->getArguments(), $currentId, $newId)
);

$definition->setMethodCalls(
$this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId)
);

$definition->setProperties(
$this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
);
}
}

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

0 comments on commit 1992c3b

Please sign in to comment.