First environment value setup - by server and client IP address.
@return string Detected environment string.
509468
public static function EnvironmentDetectByIps () {
		if (static::$environment === NULL) {
			$request = & \MvcCore\Application::GetInstance()->GetRequest();
			$serverAddress = $request->GetServerIp();
			$remoteAddress = $request->GetClientIp();
			if ($serverAddress == $remoteAddress) {
				static::$environment = static::ENVIRONMENT_DEVELOPMENT;
			} else {
				static::$environment = static::ENVIRONMENT_PRODUCTION;
			}
		}
		return static::$environment;
	}
248388
public static function getIp()
	{
		if (self::$ip === null)
		{
			$ip = self::detectAndCleanIP();

			if (!empty($ip) && ($ip != '0.0.0.0') && \function_exists('inet_pton') && \function_exists('inet_ntop'))
			{
				$myIP = @inet_pton($ip);

				if ($myIP !== false)
				{
					$ip = inet_ntop($myIP);
				}
			}

			self::setIp($ip);
		}

		return self::$ip;
	}
135160
private function getCustomerIP()
    {
        $ip = null;
        if(array_key_exists('X-Forwarded-For', $_SERVER)) {
            $ip = $_SERVER['X-Forwarded-For'];
        } elseif(array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif(array_key_exists('REMOTE_ADDR', $_SERVER)) {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        return $ip;
    }
32172
public static function getCurrentIP()
    {
        $ip = '';

        foreach (['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'] as $headerKey) {
            if ($item = getenv($headerKey)) {
                foreach (array_filter(explode(',', $item), 'trim') as $ipAddress) {
                    if ($ip = filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
                        break 2;
                    }
                }
            }
        }

        return (string) $ip;
    }
294557
protected function getEnvironment()
    {
        if ($this->environment === null) {
            $loader = new \Twig_Loader_Filesystem($this->getTemplatesDirectories());
            $this->environment = new \Twig_Environment($loader);

            $filter = new Twig_SimpleFilter(
                'write',
                function (WritableInterface $host) {
                    return $host->accept($this);
                }
            );
            $this->environment->addFilter($filter);

            $filter = new Twig_SimpleFilter(
                'slugify',
                function ($string) {
                    return StringUtils::slugify($string);
                }
            );
            $this->environment->addFilter($filter);

            $filter = new Twig_SimpleFilter(
                'html_attribute',
                function ($string) {
                    return preg_replace(array('/[^a-zA-Z0-9 -]/','/^-|-$/'), array('',''), $string);
                }
            );
            $this->environment->addFilter($filter);

            $filter = new Twig_SimpleFilter(
                'md5',
                function ($string) {
                    return md5($string);
                }
            );
            $this->environment->addFilter($filter);

            $filter = new Twig_SimpleFilter(
                'stripForm',
                function ($string) {
                    $string = str_replace("<form", "<div", $string);
                    $string = preg_replace('#<div class="form-actions">(.*?)</div>#', '', $string);
                    $string = str_replace("form-actions", "form-actions hidden", $string);
                    $string = str_replace(" form-errors", " form-errors hidden", $string);
                    $string = str_replace('"form-errors', '"form-errors hidden', $string);
                    $string = str_replace("</form>", "</div>", $string);
                    return $string;
                }
            );
            $this->environment->addFilter($filter);

            $filter = new Twig_SimpleFilter(
                'saferaw',
                function ($string) {
                    if ($string instanceof SafeString) {
                        $string = (string)$string;
                    } else {
                        $string = htmlentities($string);
                    }

                    return $string;
                }
            );
            $this->environment->addFilter($filter);

            $filter = new Twig_SimpleFilter(
                'writedata',
                function ($data) {
                    $string = ' ';

                    foreach ($data as $key => $value) {
                        $key = htmlentities($key);
                        $value = htmlentities($value);

                        $string .= "data-$key=\"$value\" ";
                    }

                    return trim($string);
                }
            );
            $this->environment->addFilter($filter);

            $requestURI = array_key_exists("REQUEST_URI", $_SERVER) === true ? $_SERVER["REQUEST_URI"] : "";
            $this->environment->addGlobal("requestURI", $requestURI);
        }

        return $this->environment;
    }
746538
public function getEnv()
    {
        if (Request::isCli()) {
            return 'cli';
        }

        if (isset($_SERVER['SERVER_NAME'])) {
            $host = $_SERVER['SERVER_NAME'];
        } else {
            $host = $_SERVER['HTTP_HOST'];
            if ($_SERVER['SERVER_PORT'] != 80) {
                $host = explode(':', $host);
                $host = $host[0];
            }
        }

        switch ($host) {
            case $_SERVER['SERVER_ADDR'] :
                // no break
            case '127.0.0.1':
                //no break
            case 'localhost':
                return 'development';
        }

        $domain = substr($host, strrpos($host, '.') + 1);

        if ($domain == 'dev' || $domain == 'loc' || $domain == 'test') {
            return 'development';
        }

        if (substr($_SERVER['HTTP_HOST'], 0, 7) == '192.168') {
            return 'development';
        }
        return 'product';
    }
346087
public  static function ip()
        {
            if (getenv("HTTP_CLIENT_IP")) {
                $ip = getenv("HTTP_CLIENT_IP");
            } elseif (getenv("HTTP_X_FORWARDED_FOR")) {
                $ip = getenv("HTTP_X_FORWARDED_FOR");
                if (strstr($ip, ',')) {
                    $tmp = explode(',', $ip);
                    $ip = trim($tmp[0]);
                }
            } else {
                $ip = getenv("REMOTE_ADDR");
            }

            return $ip;
        }
720982
public function setup(string $environment = null)
    {
        if (isset($this->initialized['setup'])) {
            return $this;
        }

        $this->initialized['setup'] = true;

        $this->measureTime('_setup', 'Site Setup', function () use ($environment) {
            // Force environment if passed to the method.
            if ($environment) {
                Setup::$environment = $environment;
            }

            $this['setup'];
            $this['streams'];
        });

        return $this;
    }
1273347
function client_ip(){
        if (isset($_SERVER)) {
            if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
                $real_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
            } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
                $real_ip = $_SERVER["HTTP_CLIENT_IP"];
            } else {
                $real_ip = $_SERVER["REMOTE_ADDR"];
            }
        } else {
            if (getenv("HTTP_X_FORWARDED_FOR")) {
                $real_ip = getenv("HTTP_X_FORWARDED_FOR");
            } else if (getenv("HTTP_CLIENT_IP")) {
                $real_ip = getenv("HTTP_CLIENT_IP");
            } else {
                $real_ip = getenv("REMOTE_ADDR");
            }
        }
        return $real_ip;
    }
177795
public static function isAdminIP() {
        if (!isset($_SERVER['REMOTE_ADDR']))
            return false;

        static $whiteList; if (!$whiteList) {
            $ips = ['127.0.0.1', $_SERVER['SERVER_ADDR']];

            if (!self::$defaultConfig)
                return in_array($_SERVER['REMOTE_ADDR'], $ips);

            $values = self::$defaultConfig->get('admin.ip.whitelist', []);
            if (!is_array($values)) $values = [$values];
            $whiteList = \array_keys(\array_flip(\array_merge($ips, $values)));
        }
        return in_array($_SERVER['REMOTE_ADDR'], $whiteList);
    }
1021462
static function GetEnvType()
	{
		//
		//	RETURN	- environment type
		//		0	- production
		//		1	- pre-production
		//		2	- development
		//		3	- local
		//		4	- test
		//
		if ( ! is_array( $_SERVER ) ||
			! array_key_exists( 'SERVER_NAME', $_SERVER ) ||
			! is_string( $_SERVER[ 'SERVER_NAME' ] ) ||
			empty( $_SERVER[ 'SERVER_NAME' ] ) )
		{
			return self::ENV_UNKNOWN;
		}

		//	...
		$nRet = self::ENV_PRODUCTION;

		//	...
		$sServerName	= strtolower( trim( $_SERVER[ 'SERVER_NAME' ] ) );
		$sRootDomain	= strtolower( trim( self::ROOT_DOMAIN ) );

		if ( 0 == strcasecmp( $sServerName, $sRootDomain ) )
		{
			//	production
			$nRet	= self::ENV_PRODUCTION;
		}
		else if ( strstr( $sServerName, sprintf( "-pre.%s", $sRootDomain ) ) )
		{
			//	pre-production
			$nRet	= self::ENV_PRE_PRODUCTION;
		}
		else if ( strstr( $sServerName, sprintf( "-dev.%s", $sRootDomain ) ) )
		{
			//	development
			$nRet	= self::ENV_DEVELOPMENT;
		}
		else if ( strstr( $sServerName, sprintf( "-loc.%s", $sRootDomain ) ) )
		{
			//	local
			$nRet	= self::ENV_LOCAL;
		}
		else if ( strstr( $sServerName, sprintf( "-test.%s", $sRootDomain ) ) )
		{
			//	test
			$nRet	= self::ENV_TEST;
		}
		else
		{
			//	test for production
			$sNeedle	= sprintf( ".%s", $sRootDomain );
			$nRightPos	= strlen( $sServerName ) - strlen( $sNeedle ) - 1;
			$nSearchPos	= strrpos( $sServerName, $sNeedle );

			if ( $nRightPos > 0 && $nRightPos === $nSearchPos )
			{
				//	production
				$nRet = self::ENV_PRODUCTION;
			}
		}

		return $nRet;
	}
302856
public static function environment()
	{
		$env = static::fw()->config->get( 'app.env', 'production' );

		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, $env ) )
					return true;

			return false;
		}

		return $env;
	}
117943
public
    static function getEnvironment()
    {
        if (empty(self::$environment)) {
            self::$environment = getenv(self::ENV)
                ?: @$_SERVER[self::ENV]
                    ?: @$_ENV[self::ENV];

            // If the environment cannot be inferred, assume production.
            if (empty(self::$environment)) {
                self::$environment = self::ENV_PRODUCTION;
            }
        }

        return self::$environment;
    }
995736
protected function set_env()
    {
        if ($this->delimiter !== null && $this->namespace !== null) {
            return;
        }

        $config         = rcube::get_instance()->config;
        $imap_personal  = $config->get('imap_ns_personal');
        $imap_other     = $config->get('imap_ns_other');
        $imap_shared    = $config->get('imap_ns_shared');
        $imap_delimiter = $config->get('imap_delimiter');

        if (!$this->check_connection()) {
            return;
        }

        $ns = $this->conn->getNamespace();

        // Set namespaces (NAMESPACE supported)
        if (is_array($ns)) {
            $this->namespace = $ns;
        }
        else {
            $this->namespace = array(
                'personal' => NULL,
                'other'    => NULL,
                'shared'   => NULL,
            );
        }

        if ($imap_delimiter) {
            $this->delimiter = $imap_delimiter;
        }
        if (empty($this->delimiter)) {
            $this->delimiter = $this->namespace['personal'][0][1];
        }
        if (empty($this->delimiter)) {
            $this->delimiter = $this->conn->getHierarchyDelimiter();
        }
        if (empty($this->delimiter)) {
            $this->delimiter = '/';
        }

        // Overwrite namespaces
        if ($imap_personal !== null) {
            $this->namespace['personal'] = NULL;
            foreach ((array)$imap_personal as $dir) {
                $this->namespace['personal'][] = array($dir, $this->delimiter);
            }
        }
        if ($imap_other !== null) {
            $this->namespace['other'] = NULL;
            foreach ((array)$imap_other as $dir) {
                if ($dir) {
                    $this->namespace['other'][] = array($dir, $this->delimiter);
                }
            }
        }
        if ($imap_shared !== null) {
            $this->namespace['shared'] = NULL;
            foreach ((array)$imap_shared as $dir) {
                if ($dir) {
                    $this->namespace['shared'][] = array($dir, $this->delimiter);
                }
            }
        }

        // Find personal namespace prefix(es) for self::mod_folder()
        if (is_array($this->namespace['personal']) && !empty($this->namespace['personal'])) {
            // There can be more than one namespace root,
            // - for prefix_out get the first one but only
            //   if there is only one root
            // - for prefix_in get the first one but only
            //   if there is no non-prefixed namespace root (#5403)
            $roots = array();
            foreach ($this->namespace['personal'] as $ns) {
                $roots[] = $ns[0];
            }

            if (!in_array('', $roots)) {
                $this->namespace['prefix_in'] = $roots[0];
            }
            if (count($roots) == 1) {
                $this->namespace['prefix_out'] = $roots[0];
            }
        }

        $_SESSION['imap_namespace'] = $this->namespace;
        $_SESSION['imap_delimiter'] = $this->delimiter;
    }
173347
public function environment()
    {
        $env = $this->getEnv();
        $name = 'Config/Environment/' . ucfirst($env) . '.php';

        foreach ($this->loader->find($name) as $file) {
            require_once $file->getRealPath();
            $class = $file->getClassName();
            $initializer = new $class();
            $initializer->configure($this);
        }
    }
526111
public function getIp()
    {
        $ip = '';

        if ($_SERVER['REMOTE_ADDR']) {
            $ip = $_SERVER['REMOTE_ADDR'];
        } elseif (getenv('HTTP_CLIENT_IP')) {
            $ip = getenv('HTTP_CLIENT_IP');
        } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
            $ip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif (getenv('HTTP_X_FORWARDED')) {
            $ip = getenv('HTTP_X_FORWARDED');
        } elseif (getenv('HTTP_FORWARDED_FOR')) {
            $ip = getenv('HTTP_FORWARDED_FOR');
        } elseif (getenv('HTTP_FORWARDED')) {
            $ip = getenv('HTTP_FORWARDED');
        }

        return $ip;
    }
1299930
public static function getEnvironment()
    {
        if (self::$_environment !== null) {
            return self::$_environment;
        }

        $language      = setlocale(LC_ALL, 0);
        $languages     = explode(';', $language);
        $languagearray = array();

        foreach ($languages as $locale) {
            if (strpos($locale, '=') !== false) {
                $language = substr($locale, strpos($locale, '='));
                $language = substr($language, 1);
            }

            if ($language !== 'C') {
                if (strpos($language, '.') !== false) {
                    $language = substr($language, 0, strpos($language, '.'));
                } else if (strpos($language, '@') !== false) {
                    $language = substr($language, 0, strpos($language, '@'));
                }

                $language = str_ireplace(
                    array_keys(Zend_Locale_Data_Translation::$languageTranslation),
                    array_values(Zend_Locale_Data_Translation::$languageTranslation),
                    (string) $language
                );

                $language = str_ireplace(
                    array_keys(Zend_Locale_Data_Translation::$regionTranslation),
                    array_values(Zend_Locale_Data_Translation::$regionTranslation),
                    $language
                );

                if (isset(self::$_localeData[$language]) === true) {
                    $languagearray[$language] = 1;
                    if (strpos($language, '_') !== false) {
                        $languagearray[substr($language, 0, strpos($language, '_'))] = 1;
                    }
                }
            }
        }

        self::$_environment = $languagearray;
        return $languagearray;
    }