Factory To Settings Environment

callable:
string|BaseEnv function()
return alias or env instance

@param string|callable $alias
@param \Traversable    $defaults

@throws \Exception
@return EnvBase
540033
static function of($alias, $defaults = null)
    {
        $EnvClass = static::createEnvInstance($alias);
        if (null !== $defaults)
            $EnvClass->import($defaults);
        
        
        return $EnvClass;
    }
2149
public function get($name, $default = null)
    {
        if (array_key_exists($name, $this->aliases)) {
            return $this->aliases[$name];
        } else {
            return $default;
        }
    }
1244148
public function alias($alias = null)
    {
        if ($alias !== null) {
            $this->setAlias($alias);
        }

        return $this->getAlias();
    }
107510
public function getEnvOption($key, $default = false)
    {
        return (array_key_exists($key, $this->_envOptions)) ? $this->_envOptions[$key] : $default;
    }
718994
public function env($name = '', $default = null, $filter = '')
    {
        if (empty($this->env)) {
            $this->env = $_ENV;
        }
        if (is_array($name)) {
            return $this->env = array_merge($this->env, $name);
        }
        return $this->input($this->env, false === $name ? false : strtoupper($name), $default, $filter);
    }
322652
public static function instanceExists($alias = null)
	{
		if('' === static::$driverName)
		{
			static::init();
		}
		return isset(self::$instances[static::$driverName][null === $alias ? self::defaultAlias() : $alias]);
	}
609126
protected function extractEnv($envs)
    {
        for ($env = null; $e = array_pop($envs);) {
            $e->parent = $env;
            $env = $e;
        }

        return $env;
    }
1277182
public static function get($key, $default = null)
    {
        $value = getenv(Str::upper($key));

        if (is_string($value)) {
            return $value;
        }

        return isset(static::$env[$key]) ? static::$env[$key] : $default;
    }
318467
protected function env($name, $defaultValue = null)
    {
        $value = getenv($name);

        if (null === $value || false === $value) {
            return $defaultValue;
        }

        return $value;
    }
762736
protected static function parseDefaults($defaults)
    {
        if (!is_string($defaults)) {
            return $defaults;
        }

        $regex = '/(?:(?<plugin>[a-zA-Z0-9\/]*)\.)?(?<prefix>[a-zA-Z0-9\/]*?)' .
            '(?:\/)?(?<controller>[a-zA-Z0-9]*):{2}(?<action>[a-zA-Z0-9_]*)/i';

        if (preg_match($regex, $defaults, $matches)) {
            foreach ($matches as $key => $value) {
                // Remove numeric keys and empty values.
                if (is_int($key) || $value === '' || $value === '::') {
                    unset($matches[$key]);
                }
            }
            $length = count($matches);

            if (isset($matches['prefix'])) {
                $matches['prefix'] = strtolower($matches['prefix']);
            }

            if ($length >= 2 || $length <= 4) {
                return $matches;
            }
        }
        throw new RuntimeException("Could not parse `{$defaults}` route destination string.");
    }
315720
public static function getEnvNameByHost(string $defaultEnv = null, string $hostname = null): string
    {
        $hostname = $hostname ?: gethostname();

        if (!$hostname) {
            return $defaultEnv;
        }

        foreach (self::$host2env as $kw => $env) {
            if (false !== strpos($hostname, $kw)) {
                return $env;
            }
        }

        return $defaultEnv;
    }
110720
public function getEnvironmentConfig($query = '', $default = null)
    {
        if ($query == '') {
            return $this->environment->getCurrentEnvironmentConfig();
        } else {
            return $this->environment->getCurrentEnvironmentConfig()->get($query, $default);
        }
    }
822374
public function get($key, $default = null)
    {
        if (\array_key_exists($key, $this->cacheEnv)) {
            return $this->cacheEnv[$key];
        }

        $envKey = $this->convertEnvKey($key);
        $envValue = getenv($envKey);

        if (false !== $envValue) {
            return $this->cacheEnv[$key] = $this->convertEnvValue($envValue, $envKey);
        }

        $defaultValue = $this->getDefaultValue($key, $default);

        return \array_key_exists($key, $this->config)
            ? $this->getByManager($key, $this->config[$key], $defaultValue)
            : $defaultValue;
    }
217328
public static function create(
        string $projectRoot, $default = self::ENV_PRODUCTION, array $allowed = []
    ): EnvironmentInterface
    {
        if (! $allowed) {
            $allowed = [
                self::ENV_PRODUCTION,
                self::ENV_STAGING,
                self::ENV_TESTING,
                self::ENV_DEVELOPMENT,
            ];
        }

        $projectRoot = realpath($projectRoot);

        $filename = $projectRoot . '/.environment';
        if (! $projectRoot || ! file_exists($filename)) {
            return new static($default, $projectRoot);
        }

        // get the environment name
        $name = file_get_contents($filename);

        if (! in_array($name, $allowed)) {
            throw new UnknownEnvironmentException(
                'Unknown environment "' . $name . '". Either add to the allowed list or provide one of: '
                . join(', ', $allowed)
            );
        }

        return new static($name, $projectRoot);
    }
1337701
public function setDefaults(array $defaults)
    {
        foreach ($this->routes as $route)
            $route->setDefaults($defaults);
        return $this;
    }
662927
public function setDefaults(array $defaults): self
    {
        foreach ((array)$defaults as $key => $value) {
            if (isset($this->defaults[$key])) {
                $this->defaults[$key] = $value;
            } else {
                throw new Exception('Invalid route default', Exception::HTTP_INTERNAL_SERVER_ERROR);
            }
        }

        return $this;
    }
200897
public function make($alias, $use_singletons=false)
	{
		$alias = strtolower($alias);

		if (! array_key_exists($alias, $this->services))
		{
			throw new \InvalidArgumentException('No Service is registered for alias: '. $alias);
		}

		// The provider could be either a string (namespaced class)
		// or a Closure that returns an instance of the desired class.
		$service = $this->services[$alias];

		if (is_string($service))
		{
			if (! class_exists($service, true))
			{
				throw new \RuntimeException('Unable to locate the Service Provider: '. $this->services[$alias] );
			}

			return $this->inject($service, $use_singletons);
		}

		else if (is_callable($service))
		{
			return $service( $this );
		}

		return null;
	}