php artisan config:cache 命令缓存./config目录下的所有配置文件到./bootstrap/cache/config.php里面
# 这里如果存在 ./config目录配置文件存在闭包函数 缓存不能被执行
public function handle()
{
// 执行清除缓存命令 就是删除config.php文件
$this->call('config:clear');
// 获取./config 配置文件信息 返回数组的形式
$config = $this->getFreshConfiguration();
// 获取需要缓存的路径./bootstrap/cache/config.php
$configPath = $this->laravel->getCachedConfigPath();
// 数据写入 var_export($config, true) 返回合法的php代码 参考该php函数
$this->files->put(
$configPath, '<?php return '.var_export($config, true).';'.PHP_EOL
);
try {
require $configPath;
} catch (Throwable $e) {
$this->files->delete($configPath);
throw new LogicException('Your configuration files are not serializable.', 0, $e);
}
$this->info('Configuration cached successfully!');
}
网友评论