8000 [DI] Deal with inlined non-shared services by nicolas-grekas · Pull Request #23005 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Deal with inlined non-shared services #23005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $co

// was the service inlined? Of so, does its parent service exist?
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setRepeatedPass(RepeatedPass $repeatedPass)
/**
* 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
*/
Expand All @@ -59,7 +59,7 @@ protected function processValue($value, $isRoot = false)

if ($this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) {
$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()) {
return $definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function testThrowExceptionIfServiceInlined()
->method('getInlinedServiceIds')
->will($this->returnValue(array(
// a_service inlined into b_service
'a_service' => 'b_service',
'a_service' => array('b_service'),
// b_service inlined into c_service
'b_service' => 'c_service',
'b_service' => array('c_service'),
)));

$container = new ContainerBuilder();
Expand Down Expand Up @@ -100,9 +100,9 @@ public function testDoNotThrowExceptionIfServiceInlinedButRemoved()
->method('getInlinedServiceIds')
->will($this->returnValue(array(
// a_service inlined into b_service
'a_service' => 'b_service',
'a_service' => array('b_service'),
// b_service inlined into c_service
'b_service' => 'c_service',
'b_service' => array('c_service'),
)));

// do NOT register c_service in the container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function testGetInlinedServiceIdData()
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass));
$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)
Expand Down
0