Checking Your Environment

Problem

You need to know the environment.

You've reached a point in your application where it would be handy to know what your environment is, but aren't sure the best way to determine this.

Solution

There are several

If you're specifically checking for local or testing you can do the following.

if (App::isLocal())
{
    echo "environment=local\n";
}
elseif (App::runningUnitTests())
{
    echo "environment=testing\n";
}

Otherwise, you can check against a list or check the environment individually.

if (App::environment('production', 'staging'))
{
    echo "I'm on production or staging\n";
}
else
{
    echo "environment=", App::environment(), "\n";
}

Discussion

The environment setting is bound to 'env' in the IoC container.

echo app('env');

See Environment Specific Configurations for details on setting the environment.

comments powered by Disqus