bug #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 | #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
-------
317e820694
[DI] fix removing non-shared definition while inlining them
This commit is contained in:
commit
8297a75eb7
@ -60,6 +60,7 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe
|
|||||||
$analyzedContainer = $container;
|
$analyzedContainer = $container;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
$remainingInlinedIds = [];
|
||||||
$this->connectedIds = $this->notInlinedIds = $container->getDefinitions();
|
$this->connectedIds = $this->notInlinedIds = $container->getDefinitions();
|
||||||
do {
|
do {
|
||||||
if ($this->analyzingPass) {
|
if ($this->analyzingPass) {
|
||||||
@ -83,8 +84,10 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->inlinedIds as $id => $isPublic) {
|
foreach ($this->inlinedIds as $id => $isPublicOrNotShared) {
|
||||||
if (!$isPublic) {
|
if ($isPublicOrNotShared) {
|
||||||
|
$remainingInlinedIds[$id] = $id;
|
||||||
|
} else {
|
||||||
$container->removeDefinition($id);
|
$container->removeDefinition($id);
|
||||||
$analyzedContainer->removeDefinition($id);
|
$analyzedContainer->removeDefinition($id);
|
||||||
}
|
}
|
||||||
@ -94,6 +97,14 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe
|
|||||||
if ($this->inlinedIds && $this->repeatedPass) {
|
if ($this->inlinedIds && $this->repeatedPass) {
|
||||||
$this->repeatedPass->setRepeat();
|
$this->repeatedPass->setRepeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($remainingInlinedIds as $id) {
|
||||||
|
$definition = $container->getDefinition($id);
|
||||||
|
|
||||||
|
if (!$definition->isShared() && !$definition->isPublic()) {
|
||||||
|
$container->removeDefinition($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
$this->container = null;
|
$this->container = null;
|
||||||
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = [];
|
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = [];
|
||||||
@ -131,7 +142,7 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe
|
|||||||
}
|
}
|
||||||
|
|
||||||
$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->inlinedIds[$id] = $definition->isPublic();
|
$this->inlinedIds[$id] = $definition->isPublic() || !$definition->isShared();
|
||||||
$this->notInlinedIds[$this->currentId] = true;
|
$this->notInlinedIds[$this->currentId] = true;
|
||||||
|
|
||||||
if ($definition->isShared()) {
|
if ($definition->isShared()) {
|
||||||
|
Reference in New Issue
Block a user