@@ -74,33 +74,7 @@ public function load(mixed $file, ?string $type = null): RouteCollection
7474 throw new \InvalidArgumentException (\sprintf ('The file "%s" must contain a YAML array. ' , $ path ));
7575 }
7676
77- foreach ($ parsedConfig as $ name => $ config ) {
78- if (str_starts_with ($ name , 'when@ ' )) {
79- if (!$ this ->env || 'when@ ' .$ this ->env !== $ name ) {
80- continue ;
81- }
82-
83- foreach ($ config as $ name => $ config ) {
84- $ this ->validate ($ config , $ name .'" when "@ ' .$ this ->env , $ path );
85-
86- if (isset ($ config ['resource ' ])) {
87- $ this ->parseImport ($ collection , $ config , $ path , $ file );
88- } else {
89- $ this ->parseRoute ($ collection , $ name , $ config , $ path );
90- }
91- }
92-
93- continue ;
94- }
95-
96- $ this ->validate ($ config , $ name , $ path );
97-
98- if (isset ($ config ['resource ' ])) {
99- $ this ->parseImport ($ collection , $ config , $ path , $ file );
100- } else {
101- $ this ->parseRoute ($ collection , $ name , $ config , $ path );
102- }
103- }
77+ $ this ->loadContent ($ collection , $ parsedConfig , $ path , $ file );
10478
10579 return $ collection ;
10680 }
@@ -273,6 +247,29 @@ protected function validate(mixed $config, string $name, string $path): void
273247 }
274248 }
275249
250+ private function loadContent (RouteCollection $ collection , array $ config , string $ path , string $ file ): void
251+ {
252+ foreach ($ config as $ name => $ config ) {
253+ if (!str_starts_with ($ when = $ name , 'when@ ' )) {
254+ $ config = [$ name => $ config ];
255+ } elseif (!$ this ->env || 'when@ ' .$ this ->env !== $ name ) {
256+ continue ;
257+ } else {
258+ $ when .= '" when "@ ' .$ this ->env ;
259+ }
260+
261+ foreach ($ config as $ name => $ config ) {
262+ $ this ->validate ($ config , $ when , $ path );
263+
264+ if (isset ($ config ['resource ' ])) {
265+ $ this ->parseImport ($ collection , $ config , $ path , $ file );
266+ } else {
267+ $ this ->parseRoute ($ collection , $ name , $ config , $ path );
268+ }
269+ }
270+ }
271+ }
272+
276273 /**
277274 * @throws \InvalidArgumentException If one of the provided config keys is not supported,
278275 * something is missing or the combination is nonsense
0 commit comments