This implements the 'singleton' design pattern

@param integer $mode Ignored rcube::get_instance() argument
@param string  $env  Environment name to run (e.g. live, dev, test)

@return rcmail The one and only instance
197117
static function get_instance($mode = 0, $env = '')
    {
        if (!self::$instance || !is_a(self::$instance, 'rcmail')) {
            self::$instance = new rcmail($env);
            // init AFTER object was linked with self::$instance
            self::$instance->startup();
        }

        return self::$instance;
    }
120762
public static function createFromEnvironment(Environment $env)
    {
        // Scheme
        $isSecure = $env->get('HTTPS');
        $scheme = (empty($isSecure) || $isSecure === 'off') ? 'http' : 'https';

        // Authority: Username and password
        $username = $env->get('PHP_AUTH_USER', '');
        $password = $env->get('PHP_AUTH_PW', '');

        // Authority: Host and Port
        if ($env->has('HTTP_HOST')) {
            $host = $env->get('HTTP_HOST');
            // set a port default
            $port = null;
        } else {
            $host = $env->get('SERVER_NAME');
            // set a port default
            $port = (int)$env->get('SERVER_PORT', 80);
        }

        if (preg_match('/^(\[[a-fA-F0-9:.]+\])(:\d+)?\z/', $host, $matches)) {
            $host = $matches[1];

            if (isset($matches[2])) {
                $port = (int) substr($matches[2], 1);
            }
        } else {
            $pos = strpos($host, ':');
            if ($pos !== false) {
                $port = (int) substr($host, $pos + 1);
                $host = strstr($host, ':', true);
            }
        }

        // Path
        $requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
        $requestScriptDir = dirname($requestScriptName);

        // parse_url() requires a full URL. As we don't extract the domain name or scheme,
        // we use a stand-in.
        $requestUri = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_PATH);

        $basePath = '';
        $virtualPath = $requestUri;
        if (stripos($requestUri, $requestScriptName) === 0) {
            $basePath = $requestScriptName;
        } elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {
            $basePath = $requestScriptDir;
        }

        if ($basePath) {
            $virtualPath = ltrim(substr($requestUri, strlen($basePath)), '/');
        }

        // Query string
        $queryString = $env->get('QUERY_STRING', '');
        if ($queryString === '') {
            $queryString = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_QUERY);
        }

        // Fragment
        $fragment = '';

        // Build Uri
        $uri = new static($scheme, $host, $port, $virtualPath, $queryString, $fragment, $username, $password);
        if ($basePath) {
            $uri = $uri->withBasePath($basePath);
        }

        return $uri;
    }
460751
private function deleteCache(string $env)
    {
        Output::displayAsSuccess("Hey, I delete cache from $env environment ", "none");
        $this->callDelCreaServer($env);
        if (in_array("--noexit", $this->options["options"])) {
            Output::displayAsEndSuccess("Cache delete for $env environment is successfull.", "none");
        } else {
            Output::displayAsNormal("Cache delete for $env environment is successfull.");
        }
    }
766584
public static function getInstance($param = null)
    {
        if (self::$instance === null) {
            if (isset($param['type'])) {
                $type = $param['type'];
                unset($param['type']);
            } else {
                throw new \LogicException('Config Type was not specified in the param array $param[\'type\']');
            }

            self::$instance = ConfigFactory::make($type, $param);
        }

        // return singelton instance
        return self::$instance;
    }
333812
public function get($instanceId)
    {
        $siteId = $this->getServiceLocator()->get(\Rcm\Service\CurrentSite::class)
            ->getSiteId();
        /** @var RcmUserService $rcmUserService */
        $rcmUserService = $this->serviceLocator->get(RcmUserService::class);

        /** @var ResourceName $resourceName */
        $resourceName = $this->getServiceLocator()->get(
            ResourceName::class
        );

        $allowed = $rcmUserService->isAllowed(
            $resourceName->get(ResourceName::RESOURCE_SITES, $siteId),
            'admin',
            \Rcm\Acl\ResourceProvider::class
        );

        if (!$allowed) {
            $this->getResponse()->setStatusCode(401);

            return $this->getResponse();
        }

        $routeMatch = $this->getEvent()->getRouteMatch();
        $pluginType = $routeMatch->getParam('pluginType');
        /**
         * @var $pluginMgr PluginManager
         */
        $pluginMgr = $this->getServiceLocator()
            ->get('Rcm\Service\PluginManager');
        $defaultInstanceCfg = $pluginMgr->getDefaultInstanceConfig($pluginType);
        if (!is_array($defaultInstanceCfg)) {
            return $this->notFoundAction();
        }

        if ($instanceId > 0) {
            try {
                $instanceConfig = $pluginMgr->getInstanceConfig($instanceId);
            } catch (PluginInstanceNotFoundException $e) {
                return $this->notFoundAction();
            }
        } else {
            $instanceConfig = $defaultInstanceCfg;
        }

        return new JsonModel(
            [
                'instanceConfig' => $instanceConfig,
                'defaultInstanceConfig' => $defaultInstanceCfg
            ]
        );
    }
332247
public function environment($env = null)
    {
        if ($env !== null) {
            // Windows nodejs needs these environment variables.
            $winenv = $this->_getenv(array('SystemDrive', 'SystemRoot'));
            $this->_env = array_merge($winenv, $env);
            return $this;
        }
        return $this->_env;
    }
449511
protected function getForm(Instance $instance = null)
    {
        if($instance == null) {
            $instance = $this->getManager()->createNew();
        }
        
        return $this->createForm(
            $this->container->get('ringo_php_redmon.form.instance_type'),
            $instance
        );
    }
727126
public function env($env, $value = null)
    {
        if (! is_array($env)) {
            $env = [$env => $value];
        }

        foreach ($env as $key => $value) {
            $this->env[$key] = $value;
        }

        return $this;
    }
539269
public function setEnv($env = null)
    {
        if (in_array($env, \WebServCo\Framework\Environment::getOptions())) {
            $this->env = $env;
        } else {
            $this->env = \WebServCo\Framework\Environment::ENV_DEV;
        }

        return true;
    }
203507
public function getEnvBaseUrl($env)
    {
        switch ($env) {
            case self::ENV_PROD:
                return self::BASE_URL_PROD;
            case self::ENV_STAGE:
                return self::BASE_URL_STAGE;
            case self::ENV_MOCK:
                return null;
        }
    }
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();
    }
30802
public function getEnvironmentRole(Environment $environment)
    {
        $access = $environment->getUser($this->id);

        return $access ? $access->role : false;
    }
1194796
public function getKeys($env, $prefix = null)
	{
		$this->validateEnvironment($env);

		$env  = $env === self::APP ? self::EXT : self::APP;
		$keys = array_keys($this->definitions[$env]);

		if ($prefix !== null) {
			$keys = array_map(function ($key) use ($prefix) {
				return $prefix . $key;
			}, $keys);
		}

		return $keys;
	}
340484
public function updateActivity(string $env):Renderer
    {
        $allowed     = $this->get("request")->get("allowed");
        $denied     = $this->get("request")->get("denied");

        if (!in_array($env, array("dev", "prod"))) {
            throw new Server500(new \ArrayObject(array("explain" => "Undefined environment $env", "solution" =>
                "Environment must be [dev or prod]")));
        }

        if (trim($allowed) == "" || trim($denied) == "") {
            return ((new Renderer())->jsonRenderer(array("code" => 500, "msg" => "Error on hosts parameters")));
        }


        $allowed = (object)(explode(";", $allowed));
        $denied = (object)(explode(";", $denied));

        $a = new \stdClass();
        $a->allowed = $allowed;
        $a->denied = $denied;

        JL::put(
            FEnv::get("framework.config").'hosts/hosts.'.$env.'.json',
            json_encode($a, JSON_PRETTY_PRINT)
        );

        return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK")));
    }
104650
public function build(): SetInspectModeRequest
	{
		$instance = new SetInspectModeRequest();
		if ($this->mode === null) {
			throw new BuilderException('Property [mode] is required.');
		}
		$instance->mode = $this->mode;
		$instance->highlightConfig = $this->highlightConfig;
		return $instance;
	}
795167
public static function getInstance()
    {
        if (!self::$_instance) {
            self::$_instance = new Environment();
            Configure::write('Environment.initialized', true);
        }

        return self::$_instance;
    }
439840
protected function buildEnvironmentVariables($env)
    {
        $variables = '';
        foreach ($env as $key => $value) {
            $variables .= $key.'='.$value.' ';
        }

        return trim($variables);
    }