minor #23005 [DI] Deal with inlined non-shared services (nicolas-grekas)
This PR was merged into the 3.3 branch.
Discussion
----------
[DI] Deal with inlined non-shared services
| Q | A
| ------------- | ---
| Branch? | 3.3
| Bug fix? | no (fixing a non released bug fix)
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
A non-shared service can be inlined several times.
Commits
-------
996698d
[DI] Deal with inlined non-shared services
This commit is contained in:
commit
744a4eb491
@ -58,7 +58,11 @@ class AutowireExceptionPass implements CompilerPassInterface
|
|||||||
|
|
||||||
// was the service inlined? Of so, does its parent service exist?
|
// was the service inlined? Of so, does its parent service exist?
|
||||||
if (isset($inlinedIds[$serviceId])) {
|
if (isset($inlinedIds[$serviceId])) {
|
||||||
return $this->doesServiceExistInTheContainer($inlinedIds[$serviceId], $container, $inlinedIds);
|
foreach ($inlinedIds[$serviceId] as $parentId) {
|
||||||
|
if ($this->doesServiceExistInTheContainer($parentId, $container, $inlinedIds)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -36,7 +36,7 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe
|
|||||||
/**
|
/**
|
||||||
* Returns an array of all services inlined by this pass.
|
* Returns an array of all services inlined by this pass.
|
||||||
*
|
*
|
||||||
* The key is the inlined service id and its value is the service it was inlined into.
|
* The key is the inlined service id and its value is the list of services it was inlined into.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -59,7 +59,7 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe
|
|||||||
|
|
||||||
if ($this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) {
|
if ($this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) {
|
||||||
$this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
|
$this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
|
||||||
$this->inlinedServiceIds[$id] = $this->currentId;
|
$this->inlinedServiceIds[$id][] = $this->currentId;
|
||||||
|
|
||||||
if ($definition->isShared()) {
|
if ($definition->isShared()) {
|
||||||
return $definition;
|
return $definition;
|
||||||
|
@ -65,9 +65,9 @@ class AutowireExceptionPassTest extends TestCase
|
|||||||
->method('getInlinedServiceIds')
|
->method('getInlinedServiceIds')
|
||||||
->will($this->returnValue(array(
|
->will($this->returnValue(array(
|
||||||
// a_service inlined into b_service
|
// a_service inlined into b_service
|
||||||
'a_service' => 'b_service',
|
'a_service' => array('b_service'),
|
||||||
// b_service inlined into c_service
|
// b_service inlined into c_service
|
||||||
'b_service' => 'c_service',
|
'b_service' => array('c_service'),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
@ -100,9 +100,9 @@ class AutowireExceptionPassTest extends TestCase
|
|||||||
->method('getInlinedServiceIds')
|
->method('getInlinedServiceIds')
|
||||||
->will($this->returnValue(array(
|
->will($this->returnValue(array(
|
||||||
// a_service inlined into b_service
|
// a_service inlined into b_service
|
||||||
'a_service' => 'b_service',
|
'a_service' => array('b_service'),
|
||||||
// b_service inlined into c_service
|
// b_service inlined into c_service
|
||||||
'b_service' => 'c_service',
|
'b_service' => array('c_service'),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
// do NOT register c_service in the container
|
// do NOT register c_service in the container
|
||||||
|
@ -273,7 +273,7 @@ class InlineServiceDefinitionsPassTest extends TestCase
|
|||||||
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass));
|
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass));
|
||||||
$repeatedPass->process($container);
|
$repeatedPass->process($container);
|
||||||
|
|
||||||
$this->assertEquals(array('inlinable.service' => 'other_service'), $inlinePass->getInlinedServiceIds());
|
$this->assertEquals(array('inlinable.service' => array('other_service')), $inlinePass->getInlinedServiceIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function process(ContainerBuilder $container)
|
protected function process(ContainerBuilder $container)
|
||||||
|
Reference in New Issue
Block a user