Exemplo n.º 1
0
 /**
  *    A support method which sets the URL (with scheme and authority as per RFC3986) to the sample test site, which' location is by default based on the currently running script.
  *
  *    @param string $auth_str      The optional userinfo (cf. RFC3986 section 3.2) part of the URI.
  *    @param string $path          Either the optional complete URL to the test site or the (relative to the starting script) path to the test sample site root directory. Default: './site/'
  *    @return string               The URL as currently configured.
  *    @access public
  */
 static function setServerUrl($auth_str = null, $path = 'site/')
 {
     global $_SERVER;
     if (empty(self::$default_server_url)) {
         $url = parse_url(strtr($path, '\\', '/'));
         // keep path? when it's a relative path and assumed relative to the running script.
         $path_is_relative = !empty($url['path']) && empty($url['host']) && $url['path'][0] != '/' && substr($path, 0, strlen($url['path'])) == $url['path'];
         // else: path is assumed to have specified a (more or less) fully qualified URL; do NOT append it to the default location as well!
         if (!empty($_SERVER['HTTP_HOST']) && !empty($_SERVER['SCRIPT_NAME'])) {
             $dflt = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on" ? "https" : "http";
             $dflt .= '://' . $_SERVER['HTTP_HOST'] . (!empty($_SERVER['SERVER_PORT']) ? ':' . $_SERVER['SERVER_PORT'] : '');
             $dflt .= strtr(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']), '\\', '/') . ($path_is_relative ? $path : '');
         } else {
             $dflt = 'http://www.lastcraft.com/test/';
         }
         $url = self::completeURL($path_is_relative ? $dflt : $path, $dflt, $auth_str);
         self::$default_server_url = $url;
     } else {
         $url = self::$default_server_url;
     }
     return $url;
 }