Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 81adcd6

Browse filesBrowse files
[DepdencyInjection] Fix costly logic when checking errored definitions
1 parent 99fa865 commit 81adcd6
Copy full SHA for 81adcd6

File tree

1 file changed

+27
-41
lines changed
Filter options

1 file changed

+27
-41
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/DefinitionErrorExceptionPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/DefinitionErrorExceptionPass.php
+27-41Lines 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
}
@@ -105,10 +68,8 @@ protected function processValue($value, bool $isRoot = false)
10568
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
10669
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
10770
$this->sourceReferences[$targetId][$this->currentId] ?? $this->sourceReferences[$targetId][$this->currentId] = true;
108-
$this->targetReferences[$this->currentId][$targetId] ?? $this->targetReferences[$this->currentId][$targetId] = true;
10971
} else {
11072
$this->sourceReferences[$targetId][$this->currentId] = false;
111-
$this->targetReferences[$this->currentId][$targetId] = false;
11273
}
11374

11475
return $value;
@@ -122,4 +83,29 @@ protected function processValue($value, bool $isRoot = false)
12283

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.