Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b33fd3

Browse files
committed
bug #17867 [DependencyInjection] replace alias in factory services (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [DependencyInjection] replace alias in factory services | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17864 | License | MIT | Doc PR | Commits ------- 56f8798 replace alias in factory services
2 parents 0807ff7 + 56f8798 commit 4b33fd3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 11 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->setFactoryService($this->updateFactoryServiceReference($definition->getFactoryService(), $currentId, $newId));
98100
}
99101
}
100102

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

123125
return $arguments;
124126
}
127+
128+
private function updateFactoryServiceReference($factoryService, $currentId, $newId)
129+
{
130+
if (null === $factoryService) {
131+
return;
132+
}
133+
134+
return $currentId === $factoryService ? $newId : $currentId;
135+
}
125136
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public function testProcess()
2121
{
2222
$container = new ContainerBuilder();
2323

24-
$container->register('a', '\stdClass');
24+
$aDefinition = $container->register('a', '\stdClass');
25+
$aDefinition->setFactoryService('b');
26+
$aDefinition->setFactoryMethod('createA');
2527

2628
$bDefinition = new Definition('\stdClass');
2729
$bDefinition->setPublic(false);
@@ -39,6 +41,7 @@ public function testProcess()
3941
$container->has('b_alias') && !$container->hasAlias('b_alias'),
4042
'->process() replaces alias to actual.'
4143
);
44+
$this->assertSame('b_alias', $aDefinition->getFactoryService());
4245
}
4346

4447
/**

0 commit comments

Comments
 (0)