Detect the application's current environment.

@param  array|string  $envs
@return string
507876
public function detectEnvironment($envs)
    {
        $args = isset($_SERVER['argv']) ? $_SERVER['argv'] : null;

        return $this['env'] = (new EnvironmentDetector())->detect($envs, $args);
    }
1287697
public static function createFromEnv(array $env)
    {
        // cache
        if (isset($env['__request_object'])) {
            return $env['__request_object'];
        }

        if (isset($env['PATH_INFO'])) {
            $path = $env['PATH_INFO'];
        } elseif (isset($env['REQUEST_URI'])) {
            $path = $env['REQUEST_URI'];
        } elseif (isset($env['_SERVER']['PATH_INFO'])) {
            $path = $env['_SERVER']['PATH_INFO'];
        } elseif (isset($env['_SERVER']['REQUEST_URI'])) {
            $path = $env['_SERVER']['REQUEST_URI'];
        } else {
            // XXX: check path or throw exception
            $path = '/';
        }

        $requestMethod = 'GET';
        if (isset($env['REQUEST_METHOD'])) {
            $requestMethod = $env['REQUEST_METHOD'];
        } else if (isset($env['_SERVER']['REQUEST_METHOD'])) { // compatibility for superglobal
            $requestMethod = $env['_SERVER']['REQUEST_METHOD'];
        }

        // create request object with request method and path,
        // we can assign other parameters later.
        $request = new self($requestMethod, $path);
        if (function_exists('getallheaders')) {
            $request->headers = getallheaders();
        } else {
            // TODO: filter array keys by their prefix, consider adding an extension function for this.
            $request->headers = self::createHeadersFromServerGlobal($env);
        }

        if (isset($env['_SERVER'])) {
            $request->serverParameters = $env['_SERVER'];
        } else {
            $request->serverParameters = $env;
        }
        $request->parameters = $env['_REQUEST'];
        $request->queryParameters = $env['_GET'];
        $request->bodyParameters = $env['_POST'];
        $request->cookieParameters = $env['_COOKIE'];
        $request->sessionParameters = $env['_SESSION'];

        return $env['__request_object'] = $request;
    }
725738
public static function getFileEnv(string $env):string
    {
        $env = strtolower($env);
        if (in_array($env, array("dev", "prod"))) {
            return (self::$env_file);
        } else {
            throw new \Exception("Environment Error : Environment $env doesn't exist");
        }
    }
903382
public function detectEnvironment($environments)
    {
        $r = Request::getInstance();
        $pos = stripos($r->server->get('SCRIPT_NAME'), DISPATCHER_FILENAME);
        if ($pos > 0) {
            //we do this because in CLI circumstances (and some random ones) we would end up with index.ph instead of index.php
            $pos = $pos - 1;
        }
        $home = substr($r->server->get('SCRIPT_NAME'), 0, $pos);
        $this['app_relative_path'] = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $home), '/');

        $args = $this->isRunThroughCommandLineInterface() && isset($_SERVER['argv']) ? $_SERVER['argv'] : null;

        $detector = new EnvironmentDetector();

        return $this->environment = $detector->detect($environments, $args);
    }
695692
final protected function getEnv() : array
    {
        $envMask = $this->contexts['env'];
        $env = empty($envMask)
            ? $_SERVER
            : array_intersect_key($_SERVER, array_flip($envMask));

        return $env;
    }
1215658
private function getEnvValue(string $envValue)
    {
        $value = $envValue;
        if (preg_match('/^\$\{(.*)\}$/', $envValue, $match)) {
            $value = env($match[1]);
        }

        return $value;
    }
739925
protected function detectWebEnvironment($environments)
	{
		$default = ClientManager::client('site', true);

		foreach ($environments as $environment => $url)
		{
			if ($client = ClientManager::client($environment, true))
			{
				$const = 'JPATH_' . strtoupper($environment);

				// To determine the current environment, we'll simply iterate through the possible
				// environments and look for the host that matches the host for this request we
				// are currently processing here, then return back these environment's names.
				if ((defined($const) && JPATH_BASE == constant($const)) || $this->request->segment(1) == $url)
				{
					return $client;
				}
			}
		}

		return $default;
	}
635030
public static function setEnv(array $env = [])
    {
        self::$envIsSet = true;

        foreach ($env as $variable => $value) {
            self::setEnvironmentVariable($variable, $value);
        }
    }
1097763
public function getEnvironment()
    {
        $fileSystem = new Filesystem();
        $environment = '';
        $environmentPath = app()->getBasePath().'/.env';
        if ($fileSystem->isFile($environmentPath)) {
            $environment = trim($fileSystem->get($environmentPath));
            $envFile = app()->getBasePath().'/.'.$environment;

            if ($fileSystem->isFile($envFile.'.env')) {
                $dotEnv = new Dotenv(app()->getBasePath().'/', '.'.$environment.'.env');
                $dotEnv->load();
            }
        }

        return $environment;
    }
581427
public static function getEvnironment($env)
    {
        // 获得全部环境描述
        $allEnv = static::environmentName();

        if ( $allEnv && array_key_exists($env, $allEnv)) {
            return $allEnv[$env];
        }

        // 否则返回第一个
        return array_pop($allEnv);
    }
190858
public static function createFromEnvironment(Environment $env)
    {
        if (is_array($env['slim.files']) && $env->has('slim.files')) {
            return $env['slim.files'];
        } elseif (! empty($_FILES)) {
            return static::parseUploadedFiles($_FILES);
        }

        return [];
    }
1324772
public static function determineAuthorization(Environment $environment)
    {
        $authorization = $environment->get('HTTP_AUTHORIZATION');
        if (!empty($authorization) || !is_callable('getallheaders')) {
            return $environment;
        }

        $headers = getallheaders();
        if (!is_array($headers)) {
            return $environment;
        }

        $headers = array_change_key_case($headers, CASE_LOWER);
        if (isset($headers['authorization'])) {
            $environment->set('HTTP_AUTHORIZATION', $headers['authorization']);
        }

        return $environment;
    }
150631
protected function currentEnvironment($environment = null, $default = 'development')
    {
        $current = ($environment === null) ? $default : $environment;
        if (empty($environment)) {
            foreach ($this->environments as $name => $config) {
                if ($this->_match($name, $config['params'])) {
                    $current = $name;
                    break;
                }
            }
        }

        return $current;
    }
234565
public function getEnv($key = null)
    {
        if ($key === null) {
            return $this->env;
        } else {
            return (isset($this->env[$key])) ? $this->env[$key] : null;
        }
    }
476556
public function detect($environments, $consoleArgs = null)
	{
		if ($consoleArgs)
		{
			return $this->detectConsoleEnvironment($environments, $consoleArgs);
		}
		else
		{
			return $this->detectWebEnvironment($environments);
		}
	}
997899
public static function createFromEnvironment(\Slim\Environment $env) {
        if (isset($env['slim.files']) && is_array($env['slim.files'])) {
            return $env['slim.files'];
        } elseif (isset($_FILES)) {
            return static::parseUploadedFiles($_FILES);
        }

        return array();
    }
699761
protected function _environmentDetector($detect)
    {
        if (isset($detect['env'])) {
            if (isset($detect['value'])) {
                return $this->getEnv($detect['env']) == $detect['value'];
            }
            if (isset($detect['pattern'])) {
                return (bool)preg_match($detect['pattern'], $this->getEnv($detect['env']));
            }
            if (isset($detect['options'])) {
                $pattern = '/' . implode('|', $detect['options']) . '/i';

                return (bool)preg_match($pattern, $this->getEnv($detect['env']));
            }
        }

        return false;
    }