laravel5.5 简单聊聊Illuminate\Foundation\Bootstrap\LoadConfiguration做了什么

文章目录

场景

  • App\Http\Kernel 在处理请求之前,完成了对几项核心bootstrap的实现, 下面来简单聊聊\Illuminate\Foundation\Bootstrap\LoadConfiguration::class

分析

  • if (file_exists($cached = $app->getCachedConfigPath())) { $items = require $cached; } 如果已经缓存了配置文件, 则直接读取缓存文件
  • $app->instance('config', $config = new Repository($items)); 则测config instance到容器,
  • if (! isset($loadedFromCache)) { $this->loadConfigurationFiles($app, $config);} 如果没有缓存配置文件 则此时config instance的items属性是空的, 所以需要加载配置文件到容器
    • $files = $this->getConfigurationFiles($app); 得到一个数组: 扫描config/*.php, 以文件名为key
    • foreach ($files as $key => $path) {$repository->set($key, require $path);} 设置config instance 的items属性
  • $app->detectEnvironment(function () use ($config) { return $config->get('app.env', 'production'); }); 设置service container的env属性, 这个值是从config/app.php中读取

总结

  • 其实这里实现的就是将config/*.php 读取到service container的过程
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值