Skip to content

Commit ab488f0

Browse files
authored
Update Config.php
1 parent 3d712c1 commit ab488f0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Config.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function merge(callable ...$providers): array
3030

3131
$cfg = [];
3232
foreach ($providers as $provider) {
33-
$cfg = array_merge_recursive($cfg, to_array($provider()));
33+
$cfg = array_merge_recursive($cfg, self::wrapCallable(to_array($provider())));
3434
}
3535

3636
return $cfg;
@@ -41,7 +41,7 @@ public static function fromCache(string $filename): array
4141
if (file_exists($filename)) {
4242
return include $filename;
4343
}
44-
44+
4545
throw new \RuntimeException('No such file '. $filename);
4646
}
4747

@@ -56,4 +56,17 @@ public static function writeCachedConfig(string $file, array $config): void
5656
{
5757
FileWriter::writeFile($file, '<?php'.PHP_EOL.' return'.VarExporter::export($config));
5858
}
59+
60+
private static function wrapCallable(array $data): array
61+
{
62+
$cfg = [];
63+
foreach ($data as $key => $value) {
64+
if ($key == ConfigProvider::dependencies) $cfg[$key] = $value;
65+
else if (is_array($value)) $cfg[$key] = self::wrapCallable($value);
66+
else if (is_callable($value)) $cfg[$key] = static fn() => $value;
67+
else $cfg[$key] = $value ;
68+
}
69+
70+
return $cfg;
71+
}
5972
}

0 commit comments

Comments
 (0)