Skip to content

Commit 2a887da

Browse files
Merge branch '6.4' into 7.0
* 6.4: [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s [Intl] fix test [Intl] Use VarExporter::export() in PhpBundleWriter [Console] The application also catch `\Throwable` exceptions FrameworkBundle] Fix tests [Mailer] Fix Brevo transport factory registration 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 55740de + 2a4e345 commit 2a887da

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

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

3433
public function process(ContainerBuilder $container): void
3534
{
3635
try {
3736
parent::process($container);
3837

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

7640
foreach ($this->erroredDefinitions as $id => $definition) {
77-
if (isset($this->sourceReferences[$id])) {
41+
if ($this->isErrorForRuntime($id, $visitedIds)) {
7842
continue;
7943
}
8044

@@ -85,7 +49,6 @@ public function process(ContainerBuilder $container): void
8549
}
8650
} finally {
8751
$this->erroredDefinitions = [];
88-
$this->targetReferences = [];
8952
$this->sourceReferences = [];
9053
}
9154
}
@@ -101,10 +64,8 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
10164
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
10265
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
10366
$this->sourceReferences[$targetId][$this->currentId] ??= true;
104-
$this->targetReferences[$this->currentId][$targetId] ??= true;
10567
} else {
10668
$this->sourceReferences[$targetId][$this->currentId] = false;
107-
$this->targetReferences[$this->currentId][$targetId] = false;
10869
}
10970

11071
return $value;
@@ -118,4 +79,29 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
11879

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

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)