Skip to content

Commit 3885c83

Browse files
Merge branch '5.4' into 6.2
* 5.4: [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s [Intl] fix test [Intl] Use VarExporter::export() in PhpBundleWriter Use triggering class to generate baseline for deprecation messages from DebugClassLoader [Security] Fix false-string handling in RememberMeAuthenticator [CssSelector] Tests on Xpath translator will always pass [Serializer] Fix Normalizer not utilizing converted name for index variadic param [DepdencyInjection] Fix costly logic when checking errored definitions fix children cond [DoctrineBridge] Load refreshed user proxy [DependencyInjection] Don't ignore attributes on the actual decorator [FrameworkBundle] Prevent `cache:clear` to lose files on subsequent runs
2 parents 462409e + cc80120 commit 3885c83

File tree

3 files changed

+40
-45
lines changed

3 files changed

+40
-45
lines changed

Compiler/DefinitionErrorExceptionPass.php

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
class DefinitionErrorExceptionPass extends AbstractRecursivePass
2727
{
2828
private $erroredDefinitions = [];
29-
private $targetReferences = [];
3029
private $sourceReferences = [];
3130

3231
/**
@@ -37,45 +36,10 @@ public function process(ContainerBuilder $container)
3736
try {
3837
parent::process($container);
3938

40-
if (!$this->erroredDefinitions) {
41-
return;
42-
}
43-
44-
$runtimeIds = [];
45-
46-
foreach ($this->sourceReferences as $id => $sourceIds) {
47-
foreach ($sourceIds as $sourceId => $isRuntime) {
48-
if (!$isRuntime) {
49-
continue 2;
50-
}
51-
}
52-
53-
unset($this->erroredDefinitions[$id]);
54-
$runtimeIds[$id] = $id;
55-
}
56-
57-
if (!$this->erroredDefinitions) {
58-
return;
59-
}
60-
61-
foreach ($this->targetReferences as $id => $targetIds) {
62-
if (!isset($this->sourceReferences[$id]) || isset($runtimeIds[$id]) || isset($this->erroredDefinitions[$id])) {
63-
continue;
64-
}
65-
foreach ($this->targetReferences[$id] as $targetId => $isRuntime) {
66-
foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
67-
if ($sourceId !== $targetId) {
68-
$this->sourceReferences[$targetId][$sourceId] = false;
69-
$this->targetReferences[$sourceId][$targetId] = false;
70-
}
71-
}
72-
}
73-
74-
unset($this->sourceReferences[$id]);
75-
}
39+
$visitedIds = [];
7640

7741
foreach ($this->erroredDefinitions as $id => $definition) {
78-
if (isset($this->sourceReferences[$id])) {
42+
if ($this->isErrorForRuntime($id, $visitedIds)) {
7943
continue;
8044
}
8145

@@ -86,7 +50,6 @@ public function process(ContainerBuilder $container)
8650
}
8751
} finally {
8852
$this->erroredDefinitions = [];
89-
$this->targetReferences = [];
9053
$this->sourceReferences = [];
9154
}
9255
}
@@ -102,10 +65,8 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
10265
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
10366
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
10467
$this->sourceReferences[$targetId][$this->currentId] ??= true;
105-
$this->targetReferences[$this->currentId][$targetId] ??= true;
10668
} else {
10769
$this->sourceReferences[$targetId][$this->currentId] = false;
108-
$this->targetReferences[$this->currentId][$targetId] = false;
10970
}
11071

11172
return $value;
@@ -119,4 +80,29 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
11980

12081
return parent::processValue($value);
12182
}
83+
84+
private function isErrorForRuntime(string $id, array &$visitedIds): bool
85+
{
86+
if (!isset($this->sourceReferences[$id])) {
87+
return false;
88+
}
89+
90+
if (isset($visitedIds[$id])) {
91+
return $visitedIds[$id];
92+
}
93+
94+
$visitedIds[$id] = true;
95+
96+
foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
97+
if ($visitedIds[$sourceId] ?? $visitedIds[$sourceId] = $this->isErrorForRuntime($sourceId, $visitedIds)) {
98+
continue;
99+
}
100+
101+
if (!$isRuntime) {
102+
return false;
103+
}
104+
}
105+
106+
return true;
107+
}
122108
}

Compiler/ResolveInstanceofConditionalsPass.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
8484
$instanceofDef->setAbstract(true)->setParent($parent ?: '.abstract.instanceof.'.$id);
8585
$parent = '.instanceof.'.$interface.'.'.$key.'.'.$id;
8686
$container->setDefinition($parent, $instanceofDef);
87-
$instanceofTags[] = $instanceofDef->getTags();
87+
$instanceofTags[] = [$interface, $instanceofDef->getTags()];
8888
$instanceofBindings = $instanceofDef->getBindings() + $instanceofBindings;
8989

9090
foreach ($instanceofDef->getMethodCalls() as $methodCall) {
@@ -123,8 +123,9 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
123123
// Don't add tags to service decorators
124124
$i = \count($instanceofTags);
125125
while (0 <= --$i) {
126-
foreach ($instanceofTags[$i] as $k => $v) {
127-
if (null === $definition->getDecoratedService() || \in_array($k, $tagsToKeep, true)) {
126+
[$interface, $tags] = $instanceofTags[$i];
127+
foreach ($tags as $k => $v) {
128+
if (null === $definition->getDecoratedService() || $interface === $definition->getClass() || \in_array($k, $tagsToKeep, true)) {
128129
foreach ($v as $v) {
129130
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
130131
continue;

Tests/Compiler/ResolveInstanceofConditionalsPassTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,26 @@ public function testDecoratorsAreNotAutomaticallyTagged()
318318
$decorator->setDecoratedService('decorated');
319319
$decorator->setInstanceofConditionals([
320320
parent::class => (new ChildDefinition(''))->addTag('tag'),
321+
self::class => (new ChildDefinition(''))->addTag('other-tag'),
321322
]);
322323
$decorator->setAutoconfigured(true);
323324
$decorator->addTag('manual');
324325

325326
$container->registerForAutoconfiguration(parent::class)
326327
->addTag('tag')
327328
;
329+
$container->registerForAutoconfiguration(self::class)
330+
->addTag('last-tag')
331+
;
328332

329333
(new ResolveInstanceofConditionalsPass())->process($container);
330334
(new ResolveChildDefinitionsPass())->process($container);
331335

332-
$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
336+
$this->assertSame([
337+
'manual' => [[]],
338+
'other-tag' => [[]],
339+
'last-tag' => [[]],
340+
], $container->getDefinition('decorator')->getTags());
333341
}
334342

335343
public function testDecoratorsKeepBehaviorDescribingTags()

0 commit comments

Comments
 (0)