Skip to content

Commit 9f41a73

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: [2.8] [Form] minor fix some tests with placeholder in AbstractLayout [DependencyInjection] fix tests Validate XLIFF translation files [DependencyInjection] replace alias in factories replace alias in factory services
2 parents 12c64ba + 4ce292a commit 9f41a73

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Compiler/ReplaceAliasByActualDefinitionPass.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ private function updateReferences($container, $currentId, $newId)
9595
$definition->setProperties(
9696
$this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
9797
);
98+
99+
$definition->setFactoryService($this->updateFactoryServiceReference($definition->getFactoryService(false), $currentId, $newId), false);
100+
$definition->setFactory($this->updateFactoryReference($definition->getFactory(), $currentId, $newId));
98101
}
99102
}
100103

@@ -122,4 +125,26 @@ private function updateArgumentReferences(array $arguments, $currentId, $newId)
122125

123126
return $arguments;
124127
}
128+
129+
private function updateFactoryServiceReference($factoryService, $currentId, $newId)
130+
{
131+
if (null === $factoryService) {
132+
return;
133+
}
134+
135+
return $currentId === $factoryService ? $newId : $currentId;
136+
}
137+
138+
private function updateFactoryReference($factory, $currentId, $newId)
139+
{
140+
if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) {
141+
return $factory;
142+
}
143+
144+
if ($currentId === (string) $factory[0]) {
145+
$factory[0] = new Reference($newId, $factory[0]->getInvalidBehavior());
146+
}
147+
148+
return $factory;
149+
}
125150
}

Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
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->setFactoryService('b', false);
27+
28+
$aDefinition->setFactory(array(new Reference('b'), 'createA'));
2529

2630
$bDefinition = new Definition('\stdClass');
2731
$bDefinition->setPublic(false);
@@ -39,6 +43,11 @@ public function testProcess()
3943
$container->has('b_alias') && !$container->hasAlias('b_alias'),
4044
'->process() replaces alias to actual.'
4145
);
46+
47+
$this->assertSame('b_alias', $aDefinition->getFactoryService(false));
48+
49+
$resolvedFactory = $aDefinition->getFactory(false);
50+
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
4251
}
4352

4453
/**

0 commit comments

Comments
 (0)