Skip to content

Commit 8297a75

Browse files
bug symfony#31088 [DI] fix removing non-shared definition while inlining them (nicolas-grekas)
This PR was merged into the 4.2 branch. Discussion ---------- [DI] fix removing non-shared definition while inlining them | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#29628 | License | MIT | Doc PR | - I didn't manage to create a specific test case but this still has 100% coverage for the added lines and fixed the reproducer (and makes sense also :) ) Commits ------- 317e820 [DI] fix removing non-shared definition while inlining them
2 parents 1d02ef2 + 317e820 commit 8297a75

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function process(ContainerBuilder $container)
6060
$analyzedContainer = $container;
6161
}
6262
try {
63+
$remainingInlinedIds = [];
6364
$this->connectedIds = $this->notInlinedIds = $container->getDefinitions();
6465
do {
6566
if ($this->analyzingPass) {
@@ -83,8 +84,10 @@ public function process(ContainerBuilder $container)
8384
}
8485
}
8586

86-
foreach ($this->inlinedIds as $id => $isPublic) {
87-
if (!$isPublic) {
87+
foreach ($this->inlinedIds as $id => $isPublicOrNotShared) {
88+
if ($isPublicOrNotShared) {
89+
$remainingInlinedIds[$id] = $id;
90+
} else {
8891
$container->removeDefinition($id);
8992
$analyzedContainer->removeDefinition($id);
9093
}
@@ -94,6 +97,14 @@ public function process(ContainerBuilder $container)
9497
if ($this->inlinedIds && $this->repeatedPass) {
9598
$this->repeatedPass->setRepeat();
9699
}
100+
101+
foreach ($remainingInlinedIds as $id) {
102+
$definition = $container->getDefinition($id);
103+
104+
if (!$definition->isShared() && !$definition->isPublic()) {
105+
$container->removeDefinition($id);
106+
}
107+
}
97108
} finally {
98109
$this->container = null;
99110
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = [];
@@ -131,7 +142,7 @@ protected function processValue($value, $isRoot = false)
131142
}
132143

133144
$this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
134-
$this->inlinedIds[$id] = $definition->isPublic();
145+
$this->inlinedIds[$id] = $definition->isPublic() || !$definition->isShared();
135146
$this->notInlinedIds[$this->currentId] = true;
136147

137148
if ($definition->isShared()) {

0 commit comments

Comments
 (0)