php创建env文件,php – 如何为dotenv提供特定于环境的.env文件(在Laravel 5中)

最后通过修改app / Providers / ConfigServiceProvider.php来解决它.创建项目时,此文件将作为存根添加到应用程序文件夹,并用于覆盖配置值.

它现在处理级联配置,因此例如config / local / app.php中的任何值都将覆盖config / app.php.正如下面的评论所说,它不处理环境配置中的匹配数组,只会替换它.但是我可以在需要时解决这个问题.

use Illuminate\Support\ServiceProvider;

use Symfony\Component\Finder\Finder;

class ConfigServiceProvider extends ServiceProvider {

/**

* Overwrite any vendor / package configuration.

*

* This service provider is intended to provide a convenient location for you

* to overwrite any "vendor" or package configuration that you may want to

* modify before the application handles the incoming request / command.

*

* Modified 2014-01-20 to allow environment specific configs to be loaded

* from app/config/[environment]/ which will cascade over the base configs.

*

* @return void

*/

public function register()

{

$config = app('config');

$envPath = app()->configPath() . '/' . getenv('APP_ENV');

foreach (Finder::create()->files()->name('*.php')->in($envPath) as $file)

{

$configName = basename($file->getRealPath(), '.php');

$oldConfigValues = $config->get($configName);

$newConfigValues = require $file->getRealPath();

// Replace any matching values in the old config with the new ones.

// Doesn't yet handle matching arrays in the config, it will just replace them.

$config->set($configName, $newConfigValues + $oldConfigValues);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值