Get or check the current application environment.

@param  mixed
@return string
486786
public function environment()
	{
		if (func_num_args() > 0)
		{
			$patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();

			foreach ($patterns as $pattern)
			{
				if (str_is($pattern, $this['env']))
				{
					return true;
				}
			}

			return false;
		}

		return $this['env'];
	}
467288
private function loadEnvironment()
    {
        /**
         * Application Environment
         */
        $required_env = [
            # application configuration
            'APP_NAME', 'APP_ENV', 'APP_KEY',

            # database configuration
            'DB_HOSTNAME', 'DB_PORT', 'DB_USERNAME', 'DB_PASSWORD', 'DB_NAME',

            # application mode
            'APP_MODE'
        ];

        $root = $_SERVER['PWD'];

        $dotenv = new Dotenv($root);
        $dotenv->overload();
        $dotenv->required($required_env);
    }
234565
public function getEnv($key = null)
    {
        if ($key === null) {
            return $this->env;
        } else {
            return (isset($this->env[$key])) ? $this->env[$key] : null;
        }
    }
1313607
protected function getHomeDir()
    {
        $home = getenv('SURF_HOME');
        if (! $home) {
            if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
                if (! getenv('APPDATA')) {
                    throw new \RuntimeException('The APPDATA or SURF_HOME environment variable must be set for composer to run correctly');
                }
                $home = Files::concatenatePaths([getenv('APPDATA'), 'Surf']);
            } else {
                if (! getenv('HOME')) {
                    throw new \RuntimeException('The HOME or SURF_HOME environment variable must be set for composer to run correctly');
                }
                $home = Files::concatenatePaths([getenv('HOME'), '.surf']);
            }
        }
        $this->ensureDirectoryExists($home);

        return $home;
    }
730808
public function getConfigDir()
    {
        $home = getenv('PHPCRSH_HOME');

        if ($home) {
            return $home;
        }
        // handle windows ..
        if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
            if (!getenv('APPDATA')) {
                throw new \RuntimeException(
                    'The APPDATA or phpcrsh_HOME environment variable must be set for phpcrsh to run correctly'
                );
            }
            $home = strtr(getenv('APPDATA'), '\\', '/').'/phpcrsh';

            return $home;
        }

        if (!getenv('HOME')) {
            throw new \RuntimeException(
                'The HOME or phpcrsh_HOME environment variable must be set for phpcrsh to run correctly'
            );
        }

        $home = rtrim(getenv('HOME'), '/').'/.phpcrsh';

        return $home;
    }
1240081
public static function env()
    {
        return function () {
            // Use credentials from environment variables, if available
            $enabled = getenv(self::ENV_ENABLED);
            if ($enabled !== false) {
                return Promise\promise_for(
                    new Configuration(
                        $enabled,
                        getenv(self::ENV_PORT) ?: self::DEFAULT_PORT,
                        getenv(self:: ENV_CLIENT_ID) ?: self::DEFAULT_CLIENT_ID
                     )
                );
            }

            return self::reject('Could not find environment variable CSM config'
                . ' in ' . self::ENV_ENABLED. '/' . self::ENV_PORT . '/'
                . self::ENV_CLIENT_ID);
        };
    }
834178
private function getEnv()
    {
        foreach (['CONVERT', 'PYTHON', 'AUDIO_BITRATE', 'STREAM'] as $var) {
            $env = getenv($var);
            if ($env) {
                $prop = lcfirst(str_replace('_', '', ucwords(strtolower($var), '_')));
                $this->$prop = $env;
            }
        }
    }
1111803
public static function choose($environment = null) {
		if (!isset($environment)) {
			if(isset($_ENV["APP_ENV"])) {
				switch($_ENV["APP_ENV"]) {
					case "dev": case "development": default:
						$environment = Environment::DEVELOPMENT; break;
					case "stage":
						$environment = Environment::STAGE; break;
					case "prod": case "production":
						$environment = Environment::PRODUCTION; break;
				}
			} else {
				switch($_SERVER["SERVER_NAME"]) {
					case "localhost":
						$environment = Environment::DEVELOPMENT; break;
					default:
						$environment = Environment::PRODUCTION; break;
				}
			}
		} else {
			$environment = Environment::DEVELOPMENT;
		}
		
		return $environment;
	}
547661
public function loadEnvironment()
    {
        // Fetch the current application environment.
        $this->environment = app()->environment();
        $this->website_id  = null;

        // Fetch the current web site data and check to see if it has an
        // alternative environment.
        $website_data = WebsiteModel::currentWebsiteData();
        if (! empty($website_data)) {
            if (! empty($website_data['environment'])) {
                $this->environment = $website_data['environment'];
            }
            // We also want the website ID
            $this->website_id = $website_data['id'];
        }

        $this->cache_key = 'site-config.' . $this->environment . '.' . $this->website_id;

        return $this;
    }
310097
public function getEnvironment()
    {
        if ($this->environment == null) {
            $this->setEnvironment($this->getRevision()->getEnvironment());
        }
        return $this->environment;
    }
684700
public Environment getEnvironment()
    {
        Environment env = ((BaseApplication)this.getApplication()).getEnvironment();
        if (env == null)
            env = Environment.getEnvironment(null);   // Never
        return env;
    }
8859
public function getDefaultEnvironment()
    {
        // if the user has configured a default database then use it,
        // providing it actually exists!
        if (isset($this->values['environments']['default_database'])) {
            if ($this->getEnvironment($this->values['environments']['default_database'])) {
                return $this->values['environments']['default_database'];
            }

            throw new \RuntimeException(sprintf(
                'The environment configuration for \'%s\' is missing',
                $this->values['environments']['default_database']
            ));
        }

        // else default to the first available one
        if (is_array($this->getEnvironments()) && count($this->getEnvironments()) > 0) {
            $names = array_keys($this->getEnvironments());

            return $names[0];
        }

        throw new \RuntimeException('Could not find a default environment');
    }
697574
public static function detect(){

        $file = Composer::getRootPath('/app/config/env.php');

        if(is_file($file)) {
            $config = include $file;
        } else {
            $config = include dirname(__DIR__).'/../config/env.php';
        }

        if(defined('ZE_ENV')){

            return ZE_ENV;

        } elseif(isset($_SERVER['ZE_ENV'])){

            define('ZE_ENV', $_SERVER['ZE_ENV']);

            return ZE_ENV;

        } elseif(is_array($config)) {

            $env = 'production';

            foreach($config as $key => $value){
                if(is_callable($value) && $value instanceof \Closure && $value()){
                    $env = $key;
                } elseif(is_string($value)) {

                    if(preg_match('/\//i', $value)){
                        // Not the safest way !
                        if(preg_match($value, getenv('HTTP_HOST') )){
                            $env = $key;
                        }
                    } else {
                        if(preg_match('/'.$value.'/i', getenv('HTTP_HOST') )){
                            $env = $key;
                        }
                    }
                }
            }

            define('ZE_ENV', $env);

            return ZE_ENV;
        }
    }
892781
protected function envPath()
    {
        if (method_exists($this->laravel, 'environmentFilePath')) {
            return $this->laravel->environmentFilePath();
        }

        return $this->laravel->basePath('.env');
    }
1257860
protected function get_env_for_read_or_fail()
    {
        try {
            return File::at($this->resolve_file_path())->load();
        } catch (\Exception $e) {
            WP_CLI::error($e->getMessage());
        }
    }
16454
public static function detectEnvironment($request = null)
    {
        if (!empty(static::$env)) {
            return static::$env;
        }

        $rules = self::get('env');

        $request = $request ? $request : Request::createFromGlobals();

        $host = $request->getHost();

        foreach ($rules as $env => $rule) {
            if (is_callable($rule)) {
                static::$env = $env;
            } elseif (preg_match($rule, $host)) {
                static::$env = $env;
                break;
            }
        }

        static::loadEnvironment(static::$env);

        return static::$env;
    }
1113742
protected function getEnv($name)
    {
        $prefix = isset(self::$config['application']['env_prefix']) ? self::$config['application']['env_prefix'] : '';
        if (array_key_exists($prefix . $name, $this->env)) {
            return $this->env[$prefix . $name];
        }

        return getenv($prefix . $name);
    }