Locker\Helpers\Helpers::getEnvironment PHP Method

getEnvironment() static public method

Gets the environment by matching a given host to a config.
static public getEnvironment ( AssocArray $config, String $givenHost ) : String
$config AssocArray Configuration mapping an environment => hosts
$givenHost String A string representing the host.
return String Matched environment from the config.
    static function getEnvironment($config, $givenHost)
    {
        foreach ($config as $environment => $hosts) {
            foreach ($hosts as $host) {
                if (str_is($host, $givenHost)) {
                    return $environment;
                }
            }
        }
    }

Usage Example

Beispiel #1
0
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.
|
*/
$env = $app->detectEnvironment(function () use($app) {
    // Attempts to set the environment using the hostname (env => hostname).
    $env = Helpers::getEnvironment(['local' => [gethostname()]], gethostname());
    if ($env) {
        return $env;
    }
    // Attempts to set the environment using the domain (env => domain).
    $env = Helpers::getEnvironment(['local' => ['127.0.0.1', 'localhost']], $app['request']->getHost());
    if ($env) {
        return $env;
    }
    // Sets environment using LARAVEL_ENV server variable if it's set.
    if (array_key_exists('LARAVEL_ENV', $_SERVER)) {
        return $_SERVER['LARAVEL_ENV'];
    }
    // Otherwise sets the environment to production or the test environment if unit testing.
    return 'production';
});
/*
|--------------------------------------------------------------------------
| Bind Paths
|--------------------------------------------------------------------------
|