Navigation Menu

Skip to content

Commit

Permalink
bug #31088 [DI] fix removing non-shared definition while inlining the…
Browse files Browse the repository at this point in the history
…m (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 | #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
  • Loading branch information
nicolas-grekas committed Apr 12, 2019
2 parents 1d02ef2 + 317e820 commit 8297a75
Showing 1 changed file with 14 additions and 3 deletions.
Expand Up @@ -60,6 +60,7 @@ public function process(ContainerBuilder $container)
$analyzedContainer = $container;
}
try {
$remainingInlinedIds = [];
$this->connectedIds = $this->notInlinedIds = $container->getDefinitions();
do {
if ($this->analyzingPass) {
Expand All @@ -83,8 +84,10 @@ public function process(ContainerBuilder $container)
}
}

foreach ($this->inlinedIds as $id => $isPublic) {
if (!$isPublic) {
foreach ($this->inlinedIds as $id => $isPublicOrNotShared) {
if ($isPublicOrNotShared) {
$remainingInlinedIds[$id] = $id;
} else {
$container->removeDefinition($id);
$analyzedContainer->removeDefinition($id);
}
Expand All @@ -94,6 +97,14 @@ public function process(ContainerBuilder $container)
if ($this->inlinedIds && $this->repeatedPass) {
$this->repeatedPass->setRepeat();
}

foreach ($remainingInlinedIds as $id) {
$definition = $container->getDefinition($id);

if (!$definition->isShared() && !$definition->isPublic()) {
$container->removeDefinition($id);
}
}
} finally {
$this->container = null;
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = [];
Expand Down Expand Up @@ -131,7 +142,7 @@ protected function processValue($value, $isRoot = false)
}

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

if ($definition->isShared()) {
Expand Down

0 comments on commit 8297a75

Please sign in to comment.