77use Laminas \ConfigAggregator \ConfigAggregator ;
88use Psr \Container \ContainerInterface ;
99use Webimpress \SafeWriter \FileWriter ;
10- use function Bermuda \Stdlib \to_array ;
1110
1211final class Config implements \Countable, \IteratorAggregate, \ArrayAccess, Arrayable
1312{
@@ -155,7 +154,7 @@ public static function merge(callable ...$providers): array
155154 {
156155 $ cfg = [self ::app_debug_mode_enable => self ::$ devMode ];
157156 foreach ($ providers as $ provider ) {
158- foreach (to_array ( $ provider () ) as $ key => $ value ) {
157+ foreach ($ provider () as $ key => $ value ) {
159158 if ($ key === ConfigProvider::dependencies) {
160159 foreach ($ value as $ dependencyKey => $ dependencyValue ) {
161160 foreach ($ dependencyValue as $ k => $ v ) {
@@ -167,13 +166,13 @@ public static function merge(callable ...$providers): array
167166 $ cfg [$ key ] = [];
168167 }
169168
170- if (is_array ($ value )) $ cfg [$ key ] = array_merge ($ cfg [$ key ], self :: wrapCallable ( $ value) );
171- else $ cfg [$ key ][] = self :: wrapCallable ( $ value) ;
169+ if (is_array ($ value )) $ cfg [$ key ] = array_merge ($ cfg [$ key ], $ value );
170+ else $ cfg [$ key ][] = $ value ;
172171 } else {
173172 if (array_key_exists ($ key , $ cfg ) && is_array ($ cfg [$ key ])) {
174- if (is_array ($ value )) $ cfg [$ key ] = array_merge ($ cfg [$ key ], self :: wrapCallable ( $ value) );
175- else $ cfg [$ key ] = self :: wrapCallable ( $ value) ;
176- } else $ cfg [$ key ] = self :: wrapCallable ( $ value) ;
173+ if (is_array ($ value )) $ cfg [$ key ] = array_merge ($ cfg [$ key ], $ value );
174+ else $ cfg [$ key ] = $ value ;
175+ } else $ cfg [$ key ] = $ value ;
177176 }
178177 }
179178
@@ -202,18 +201,4 @@ public static function writeCachedConfig(string $file, array $config): void
202201 {
203202 FileWriter::writeFile ($ file , '<?php ' .PHP_EOL .' return ' .VarExporter::export ($ config ));
204203 }
205-
206- private static function wrapCallable (mixed $ var ): mixed
207- {
208- if (is_array ($ var )) {
209- foreach ($ var as $ key => &$ value ) {
210- if (is_array ($ value )) $ value = self ::wrapCallable ($ value );
211- else if (is_callable ($ value )) $ value = static fn () => $ value ;
212- }
213-
214- return $ var ;
215- }
216-
217- return is_callable ($ var ) ? static fn () => $ var : $ var ;
218- }
219204}
0 commit comments