Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cfe528e

Browse filesBrowse files
committed
[DependencyInjection] replace alias in factories
1 parent 653428a commit cfe528e
Copy full SHA for cfe528e

File tree

Expand file treeCollapse file tree

2 files changed

+21
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ private function updateReferences($container, $currentId, $newId)
9595
$definition->setProperties(
9696
$this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
9797
);
98+
99+
$definition->setFactory($this->updateFactoryReference($definition->getFactory(), $currentId, $newId));
98100
}
99101
}
100102

@@ -122,4 +124,17 @@ private function updateArgumentReferences(array $arguments, $currentId, $newId)
122124

123125
return $arguments;
124126
}
127+
128+
private function updateFactoryReference($factory, $currentId, $newId)
129+
{
130+
if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) {
131+
return $factory;
132+
}
133+
134+
if ($currentId === (string) $factory[0]) {
135+
$factory[0] = new Reference($newId, $factory[0]->getInvalidBehavior());
136+
}
137+
138+
return $factory;
139+
}
125140
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\Reference;
1718

1819
class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
1920
{
2021
public function testProcess()
2122
{
2223
$container = new ContainerBuilder();
2324

24-
$container->register('a', '\stdClass');
25+
$aDefinition = $container->register('a', '\stdClass');
26+
$aDefinition->setFactory(array(new Reference('b'), 'createA'));
2527

2628
$bDefinition = new Definition('\stdClass');
2729
$bDefinition->setPublic(false);
@@ -39,6 +41,9 @@ public function testProcess()
3941
$container->has('b_alias') && !$container->hasAlias('b_alias'),
4042
'->process() replaces alias to actual.'
4143
);
44+
45+
$resolvedFactory = $aDefinition->getFactory();
46+
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
4247
}
4348

4449
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.