Skip to content

Commit ee856f9

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Validate XLIFF translation files [DependencyInjection] replace alias in factories replace alias in factory services
2 parents 599f413 + e38fd4e commit ee856f9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-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(), $currentId, $newId));
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
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');
27+
$aDefinition->setFactoryMethod('createA');
28+
29+
$aDefinition->setFactory(array(new Reference('b'), 'createA'));
2530

2631
$bDefinition = new Definition('\stdClass');
2732
$bDefinition->setPublic(false);
@@ -39,6 +44,11 @@ public function testProcess()
3944
$container->has('b_alias') && !$container->hasAlias('b_alias'),
4045
'->process() replaces alias to actual.'
4146
);
47+
48+
$this->assertSame('b_alias', $aDefinition->getFactoryService());
49+
50+
$resolvedFactory = $aDefinition->getFactory();
51+
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
4252
}
4353

4454
/**

0 commit comments

Comments
 (0)