/** * Get the instance of the environment * @return Environment */ public static function getInstance() { if (self::$instance == null) { $cli = new Cli(); if ($cli->isCli()) { self::$instance = new CliEnvironment($cli); } else { self::$instance = new WebEnvironment(); } } return self::$instance; }
/** * Gets a instance of the current environment * @return Environment */ public static function getEnvironment() { $cli = new Cli(); if ($cli->isCli()) { return new CliEnvironment($cli); } return new WebEnvironment(); }
/** * Get the base URL of the system * * <p>This method will check first for a set URL in the Zibo configuration. If not set * the URL will be generated from the $_SERVER array.</p> * <p>If the system is run from CLI and no URL is set, the filename of the script will be returned.</p> * @return string * @throws zibo\ZiboException when the server name could not be determined */ public static function getSystemBaseUrl() { if (self::$systemBaseUrl) { return self::$systemBaseUrl; } $url = Zibo::getInstance()->getConfigValue(self::CONFIG_URL); if ($url) { return self::$systemBaseUrl = rtrim($url, '/'); } if (!array_key_exists('SERVER_NAME', $_SERVER)) { $cli = new Cli(); if ($cli->isCli() && array_key_exists('SCRIPT_FILENAME', $_SERVER)) { return $_SERVER['SCRIPT_FILENAME']; } throw new ZiboException('Could not determine the server name of this installation. Please set \'' . self::CONFIG_URL . '\' in your configuration.'); } if (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on') { $url = 'https://'; } else { $url = 'http://'; } $url .= $_SERVER['SERVER_NAME']; $port = $_SERVER['SERVER_PORT']; if (!empty($port) && $port != 80) { $url .= ':' . $port; } $script = $_SERVER['SCRIPT_NAME']; if (strpos($script, '/') === false) { $script = '/' . $script; } $url .= $script; return self::$systemBaseUrl = dirname($url); }