在Laravel 4中更改默认环境 [英] Changing default environment in Laravel 4

查看:80
本文介绍了在Laravel 4中更改默认环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel 4中,默认配置环境为生产".这意味着,如果您在不使用--env选项的情况下运行artisan命令,则该命令将采用生产配置.在未设置--env选项的情况下,由detectConsoleEnvironment()调用的\Illuminate\Foundation\Application::detectWebEnvironment()中可以看到这一点.

In Laravel 4 the default configuration environment is 'production'. This means that if you run an artisan command without the --env option, it assumes the production configuration. This can be seen in \Illuminate\Foundation\Application::detectWebEnvironment() which is called by detectConsoleEnvironment() when no --env option is set.

这种行为已成为我开发环境中的一种风险.忘记--env选项很容易,例如,无意间在您的生产数据库上运行了迁移. (是的,这发生了,但是幸运的是,这是一个很小的更改.)我接近将生产环境配置重命名为真实生产",但是似乎应该有一个更优雅的解决方案.

This behavior has become a risk with my development environment. It's really easy to forget the --env option and, say, unintentionally run a migration on your production database. (Yes, that happened but thankfully it was a minor change.) I'm close to just renaming my production environment config to 'real-production' but it seems like there should be a more elegant solution.

TL; DR

如何更改Laravel 4中的默认环境,以使artisan命令默认不在生产环境中运行?

How can I change the default environment in Laravel 4 such that artisan commands do not run on production by default?

推荐答案

感谢Antonio提示我重新考虑域检测.

Thanks Antonio for prompting me to reconsider domain detection.

$env = $app->detectEnvironment(array(
(
    // Empty string is to set development as the default environment for 
    // artisan commands.
    'development' => array('dev.foo.com', ''),
    'test' => array('test.foo.com'),
    'production' => array('www.foo.com', 'foo.com'),
));

将''添加为开发域可以有效地将开发设置为artisan命令的默认环境,大概是因为从命令行调用该应用程序时该域名为空.我测试过,看来== false都可以用.我还验证了这不会干扰对生产或测试环境的检测.

Adding '' as a development domain effectively sets development as the default environment for artisan commands, presumably because the domain name is blank when the application is invoked from the command line. I tested and it seems anything == false will work. I also verified this does not interfere with the detection of the production or testing environments.

这篇关于在Laravel 4中更改默认环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆