@@ -78,6 +78,8 @@ public function __construct(
78
78
public function load (array $ exclude = [])
79
79
{
80
80
$ result = [];
81
+ $ excludeSet = array_flip ($ exclude );
82
+
81
83
foreach ($ this ->getModuleConfigs () as list ($ file , $ contents )) {
82
84
try {
83
85
$ this ->parser ->loadXML ($ contents );
@@ -93,7 +95,7 @@ public function load(array $exclude = [])
93
95
94
96
$ data = $ this ->converter ->convert ($ this ->parser ->getDom ());
95
97
$ name = key ($ data );
96
- if (!in_array ( $ name , $ exclude )) {
98
+ if (!isset ( $ excludeSet [ $ name ] )) {
97
99
$ result [$ name ] = $ data [$ name ];
98
100
}
99
101
}
@@ -140,15 +142,15 @@ private function sortBySequence(array $origList): array
140
142
141
143
$ expanded [] = [
142
144
'name ' => $ moduleName ,
143
- 'sequence ' => $ sequence ,
145
+ 'sequence_set ' => array_flip ( $ sequence) ,
144
146
];
145
147
}
146
148
147
149
// Use "bubble sorting" because usort does not check each pair of elements and in this case it is important
148
150
$ total = count ($ expanded );
149
151
for ($ i = 0 ; $ i < $ total - 1 ; $ i ++) {
150
152
for ($ j = $ i ; $ j < $ total ; $ j ++) {
151
- if (in_array ($ expanded [$ j ]['name ' ], $ expanded [$ i ]['sequence ' ], true )) {
153
+ if (isset ($ expanded [$ i ]['sequence_set ' ][ $ expanded [$ j ]['name ' ]] )) {
152
154
$ temp = $ expanded [$ i ];
153
155
$ expanded [$ i ] = $ expanded [$ j ];
154
156
$ expanded [$ j ] = $ temp ;
@@ -196,18 +198,19 @@ private function prearrangeModules(array $modules): array
196
198
*/
197
199
private function expandSequence ($ list , $ name , $ accumulated = [])
198
200
{
199
- $ accumulated [] = $ name ;
201
+ $ accumulated [$ name ] = true ;
200
202
$ result = $ list [$ name ]['sequence ' ];
203
+ $ allResults = [];
201
204
foreach ($ result as $ relatedName ) {
202
- if (in_array ( $ relatedName , $ accumulated )) {
203
- throw new \Exception ("Circular sequence reference from ' {$ name }' to ' {$ relatedName }'. " );
205
+ if (isset ( $ accumulated[ $ relatedName ] )) {
206
+ throw new \LogicException ("Circular sequence reference from ' {$ name }' to ' {$ relatedName }'. " );
204
207
}
205
208
if (!isset ($ list [$ relatedName ])) {
206
209
continue ;
207
210
}
208
- $ relatedResult = $ this ->expandSequence ($ list , $ relatedName , $ accumulated );
209
- $ result = array_unique (array_merge ($ result , $ relatedResult ));
211
+ $ allResults [] = $ this ->expandSequence ($ list , $ relatedName , $ accumulated );
210
212
}
211
- return $ result ;
213
+ $ allResults [] = $ result ;
214
+ return array_unique (array_merge (...$ allResults ));
212
215
}
213
216
}
0 commit comments