26
26
class DefinitionErrorExceptionPass extends AbstractRecursivePass
27
27
{
28
28
private $ erroredDefinitions = [];
29
- private $ targetReferences = [];
30
29
private $ sourceReferences = [];
31
30
32
31
/**
@@ -37,45 +36,10 @@ public function process(ContainerBuilder $container)
37
36
try {
38
37
parent ::process ($ container );
39
38
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 = [];
76
40
77
41
foreach ($ this ->erroredDefinitions as $ id => $ definition ) {
78
- if (isset ( $ this ->sourceReferences [ $ id] )) {
42
+ if ($ this ->isErrorForRuntime ( $ id, $ visitedIds )) {
79
43
continue ;
80
44
}
81
45
@@ -86,7 +50,6 @@ public function process(ContainerBuilder $container)
86
50
}
87
51
} finally {
88
52
$ this ->erroredDefinitions = [];
89
- $ this ->targetReferences = [];
90
53
$ this ->sourceReferences = [];
91
54
}
92
55
}
@@ -105,10 +68,8 @@ protected function processValue($value, bool $isRoot = false)
105
68
if ($ value instanceof Reference && $ this ->currentId !== $ targetId = (string ) $ value ) {
106
69
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $ value ->getInvalidBehavior ()) {
107
70
$ this ->sourceReferences [$ targetId ][$ this ->currentId ] ?? $ this ->sourceReferences [$ targetId ][$ this ->currentId ] = true ;
108
- $ this ->targetReferences [$ this ->currentId ][$ targetId ] ?? $ this ->targetReferences [$ this ->currentId ][$ targetId ] = true ;
109
71
} else {
110
72
$ this ->sourceReferences [$ targetId ][$ this ->currentId ] = false ;
111
- $ this ->targetReferences [$ this ->currentId ][$ targetId ] = false ;
112
73
}
113
74
114
75
return $ value ;
@@ -122,4 +83,29 @@ protected function processValue($value, bool $isRoot = false)
122
83
123
84
return parent ::processValue ($ value );
124
85
}
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
+ }
125
111
}
0 commit comments