如何优雅的使 Lumen 的配置文件为 Laravel 风格?
Lumen 配置文件使用的是 .env, 虽然可以使用根目录下的 config文件夹下的配置文件,但先需要在bootstrap/app.php
中
$app->configure('xx');
否则 Config::get('xx.yy')
(已开启Config的Facade) 取不到值。
那么有什么比较优雅的方式可以自动载入config文件夹下的文件?
目前只想到遍历config文件夹下php文件再 $app->configure('xx');
use Symfony\Component\Finder\Finder;
class_alias('Illuminate\Support\Facades\Config', 'Config');
foreach (Finder::create()->files()->name('*.php')->in($app->basePath('config')) as $file)
{
$filename = trim($file->getFileName(), '.php');
if(!empty($filename)){
$app->configure($filename);
}
}
foreach (glob(__DIR__ . '/../config/*.php') as $path) {
if ($path) {
$pathInfo = pathinfo(basename($path));
$app->make('config')->set($pathInfo['filename'], require realpath($path));
}
}