コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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();
 }
コード例 #3
0
 /**
  * Gets all the query parameters of this environment
  * @return array
  */
 public function getQueryArguments()
 {
     return $this->cli->getArguments();
 }
コード例 #4
0
 /**
  * Get a argument of this environment
  * @param string $name name of the argument
  * @param mixed $default default value for when the argument is not set
  * @return mixed the value of the argument or the provided default value if the value is not set
  */
 public function getArgument($name, $default = null)
 {
     return $this->cli->getArgument($name, $default);
 }
コード例 #5
0
ファイル: Url.php プロジェクト: BGCX261/zibo-svn-to-git
 /**
  * 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);
 }