Skip to content

Commit 2a4e345

Browse files
Merge branch '6.3' into 6.4
* 6.3: [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s [Intl] fix test [Intl] Use VarExporter::export() in PhpBundleWriter Simplify tests [Notifier] Fix Esendex messages serialization 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 merge 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 a6134de + 7a8fead commit 2a4e345

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
@@ -28,7 +28,6 @@ class DefinitionErrorExceptionPass extends AbstractRecursivePass
2828
protected bool $skipScalars = true;
2929

3030
private array $erroredDefinitions = [];
31-
private array $targetReferences = [];
3231
private array $sourceReferences = [];
3332

3433
/**
@@ -39,45 +38,10 @@ public function process(ContainerBuilder $container)
3938
try {
4039
parent::process($container);
4140

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

7943
foreach ($this->erroredDefinitions as $id => $definition) {
80-
if (isset($this->sourceReferences[$id])) {
44+
if ($this->isErrorForRuntime($id, $visitedIds)) {
8145
continue;
8246
}
8347

@@ -88,7 +52,6 @@ public function process(ContainerBuilder $container)
8852
}
8953
} finally {
9054
$this->erroredDefinitions = [];
91-
$this->targetReferences = [];
9255
$this->sourceReferences = [];
9356
}
9457
}
@@ -104,10 +67,8 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
10467
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
10568
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
10669
$this->sourceReferences[$targetId][$this->currentId] ??= true;
107-
$this->targetReferences[$this->currentId][$targetId] ??= true;
10870
} else {
10971
$this->sourceReferences[$targetId][$this->currentId] = false;
110-
$this->targetReferences[$this->currentId][$targetId] = false;
11172
}
11273

11374
return $value;
@@ -121,4 +82,29 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
12182

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

Compiler/ResolveInstanceofConditionalsPass.php

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

9393
foreach ($instanceofDef->getMethodCalls() as $methodCall) {
@@ -126,8 +126,9 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
126126
// Don't add tags to service decorators
127127
$i = \count($instanceofTags);
128128
while (0 <= --$i) {
129-
foreach ($instanceofTags[$i] as $k => $v) {
130-
if (null === $definition->getDecoratedService() || \in_array($k, $tagsToKeep, true)) {
129+
[$interface, $tags] = $instanceofTags[$i];
130+
foreach ($tags as $k => $v) {
131+
if (null === $definition->getDecoratedService() || $interface === $definition->getClass() || \in_array($k, $tagsToKeep, true)) {
131132
foreach ($v as $v) {
132133
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
133134
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)