获得Lavalvel 4.2环境的最佳实践


Best practice to obtain Lavavel 4.2 Environment

在Laravel 4.2框架中,我在app/mypackages下创建了自己的psr-4 php类。

在其中一个类中,我想检查这样的环境:

    $environment = Application::environment();
    or
    $environment = Cache::get('environment');

但两者都不起作用。在第一个示例中,我收到以下错误。

Non-static method Illuminate'Foundation'Application::environment() should not be called statically, assuming $this from incompatible context

$app变量在此上下文中不可用。获取环境并使$app实例可用于获取环境和配置文件夹中的一些环境相关变量的最佳做法是什么?

相对较新的拉拉维尔,所以任何见解都非常感谢。

有几种方法。试试这些:

App::environment()
app()->environment()
app()->env
$GLOBALS['env'] // not recommended - but it is possible