Build a URL to a volume server path.

@param $host
@param null $path
@return string
483512
public function buildVolumeUrl($host, $path = null) {
        return sprintf('%s://%s/%s', $this->scheme, $host, $path ? ltrim($path, '/') : '');
    }
524246
public static function makeUriString($host, $path, $query = '', $port = null, $scheme = 'http', $fragment = '', $userInfo = '')
    {
        $uri = '';
        // 协议
        if('' !== $scheme)
        {
            $uri = $scheme . '://';
        }
        // 用户信息
        if('' !== $userInfo)
        {
            $uri .= $userInfo . '@';
        }
        // 主机+端口
        $uri .= $host. (null === $port ? '' : (':' . $port));
        // 路径
        $uri .= '/' . ltrim($path, '/');
        // 查询参数
        $uri .= ('' === $query ? '' : ('?' . $query));
        // 锚点
        $uri .= ('' === $fragment ? '' : ('#' . $fragment));
        return $uri;
    }
674334
private function getHostIfNull($host)
    {
        if ($host === null) {
            $host = $this->header->get('HOST');
        }

        if ($host === null) {
            $host = $this->server->get('SERVER_NAME');
        }

        if ($host === null) {
            // Return an empty string by default so we can do string operations on it later
            $host = $this->server->get('SERVER_ADDR', '');
        }

        return $host;
    }
770891
public function validateHost($host = null)
    {
        if ($host === null) {
            $parsed = parse_url($this->uri);
            $host = isset($parsed['host']) ? $parsed['host'] : $parsed['path'];
        }
        return (
            preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $host) //valid chars check
            && preg_match("/^.{1,253}$/", $host) //overall length check
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $host) //length of each label
            && !$this->validateIP($host)
        );
    }
807801
protected function addPathToViewPaths(array &$paths, $host)
    {
        $path = $this->createViewPath($host);

        if ($path && !in_array($path, $paths)) {
            $paths[] = $path;
        }

        return $path;
    }
883278
protected function buildHttpRequest($path, $hostname)
    {
        $r = array();
        $r[] = "GET {$path} HTTP/1.1";
        $r[] = "Host: {$hostname}";
        $r[] = "Connection: Close";
        $r[] = "User-Agent: HttpAdapter PHP-Library";
        $r[] = "\r\n";

        return implode("\r\n", $r);
    }
1132249
public function host($host = null)
    {
        $this->host = empty($host) ? null : $host;

        return $this->host;
    }
13098
public static function url(string $path, $uri)
  {
    $path = substr($path, 0, 1) != '/' ? '/' . $path : $path;

    $root = isset($_SERVER["SCRIPT_NAME"]) ? $_SERVER['SCRIPT_NAME'] : '';
    $dir = pathinfo($root)['dirname'];

    if (isset($_SERVER['HTTP_HOST'])) {
      if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
        $http = 'https://';
      } else {
        $http = 'http://';
      }

      $url = $http . $_SERVER['HTTP_HOST'] . ($dir == '/' ? '' : $dir) . $path;
    } else {
      $url = ($uri ? config('app.url') : '') . $path;
    }

    if (isset($_SERVER['QUERY_STRING'])) {
      if (str_contains($url, '?')) $url .= '&' . $_SERVER['QUERY_STRING'];
      if (!str_contains($url, '?')) $url .= '?' . $_SERVER['QUERY_STRING'];
    }

    return $url;
  }
594646
public static function getLocalPath($path, $webDir, $hostPattern = '/(.*)+/')
    {
        if (false !== strpos($path, '://')) {
            $url = parse_url($path);

            if (isset($url['host'], $url['path'])
                    && preg_match($hostPattern, $url['host'], $matches)) {
                $path = static::getExistingPath($url['path'], $webDir, $path);
            }
        } else {
            $path = static::getExistingPath($path, $webDir);
        }

        return $path;
    }
1210170
public function getHostRoot($host)
    {
        $root_path = $this->httpRoot[$host]['root'] ?? '';
        if (empty($root_path)) {
            $root_path = $this->httpRoot['default']['root'] ?? '';
        }
        if (!empty($root_path)) {
            $root_path = WWW_DIR . "/$root_path/";
        } else {
            $root_path = WWW_DIR . "/";
        }
        return $root_path;
    }
404924
public static function parse_host($host) {
		// Try to parse it the easy way.
		$tmp = v_mb::parse_url($host, \PHP_URL_HOST);
		if ($tmp) {
			$host = $tmp;
		}
		// Or the hard way?
		else {
			r_cast::string($host, true);

			r_mb::trim($host);

			// Cut off the path, if any.
			if (false !== ($start = v_mb::strpos($host, '/'))) {
				$host = v_mb::substr($host, 0, $start);
			}

			// Cut off the query, if any.
			if (false !== ($start = v_mb::strpos($host, '?'))) {
				$host = v_mb::substr($host, 0, $start);
			}

			// Cut off credentials, if any.
			if (false !== ($start = v_mb::strpos($host, '@'))) {
				$host = v_mb::substr($host, $start + 1, null);
			}

			// Is this an IPv6 address?
			if (\filter_var($host, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
				r_sanitize::ip($host, true);
			}
			elseif (
				(0 === \strpos($host, '[')) &&
				false !== ($end = v_mb::strpos($host, ']'))
			) {
				$host = v_mb::substr($host, 1, $end - 1);
				r_sanitize::ip($host, true);
			}
			// Cut off port, if any.
			elseif (false !== ($start = v_mb::strpos($host, ':'))) {
				$host = v_mb::substr($host, 0, $start);
			}

			// If it is empty or invalid, there is nothing we can do.
			if (! \strlen($host)) {
				return false;
			}

			// Convert to ASCII if possible.
			if (\function_exists('idn_to_ascii')) {
				$host = \explode('.', $host);
				r_file::idn_to_ascii($host);
				$host = \implode('.', $host);
			}

			// Lowercase it.
			r_mb::strtolower($host, false);

			// Get rid of trailing periods.
			$host = \ltrim($host, '.');
			$host = \rtrim($host, '.');
		}

		// Liberate IPv6 from its walls.
		if (0 === \strpos($host, '[')) {
			$host = \str_replace(array('[', ']'), '', $host);
			r_sanitize::ip($host, true);
		}

		// Is this an IP address? If so, we're done!
		if (\filter_var($host, \FILTER_VALIDATE_IP)) {
			return $host;
		}

		// Look for illegal characters. At this point we should
		// only have nice and safe ASCII.
		if (\preg_match('/[^a-z\d\-\.]/u', $host)) {
			return false;
		}
		$host = \explode('.', $host);
		foreach ($host as $v) {
			// Gotta have length, and can't start or end with a dash.
			if (
				! \strlen($v) ||
				(0 === \strpos($v, '-')) ||
				('-' === \substr($v, -1))
			) {
				return false;
			}
		}

		return \implode('.', $host);
	}
85399
private function getUrl($path, $parameters = [])
    {
        $url = sprintf(
            '%s/v%d/%s?client_id=%s&client_secret=%s&v=%s%s',
            $this->configuration->getBasePath(),
            urlencode($this->configuration->getVersion()),
            trim($path, '/'),
            urlencode($this->configuration->getClientId()),
            urlencode($this->configuration->getClientSecret()),
            urlencode($this->configuration->getVersionedDate()),
            $this->parseParameters($parameters)
        );

        return $url;
    }
1271468
protected function normalizeHost($host) {
		if ($host instanceof Url) {
			return $host;
		}
		
		if (is_numeric($host)) {
			return new Url(['port' => $host]);
		}
		
		if (is_string($host) && ! preg_match('~^[a-z]://~', $host)) {
			return new Url('mongodb://' . $host);
		}
		
		return new Url($host);
	}
921552
public function baseURL($path = '')
    {
        if (is_null($this->baseURL)) {
            $self = $_SERVER['PHP_SELF'];
            $server = $_SERVER['HTTP_HOST']
                      . rtrim(str_replace(strstr($self, 'index.php'), '', $self), '/');

            if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
                || !empty($_SERVER['HTTP_X_FORWARDED_PROTO'])
                && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'
            ) {
                $protocol = 'https://';
            } else {
                $protocol = 'http://';
            }

            $this->baseURL = $protocol . $server;
        }

        $url = $this->baseURL;

        if ($path !== '') {
            $url .= '/' . $path;
        }

        return $url;
    }
318751
public final function withHost($host): UriInterface
   {
       if (!is_string($host) || !($parsedHost = $this->parseHost($host))) {
           throw new InvalidArgumentException(
               "Can't get with host: invalid host name");
       }
       return $this->with("host", $parsedHost);
   }
855166
private function httpGet($host, $path, $data)
    {
        $host = sprintf("%s%s?%s", $host, $path, http_build_query($data, null, "&"));

        $context = $this->getResourceContext();

        return file_get_contents($host, false, $context);
    }
288836
static function path_to_url( $path )
    {
        // We are replacing DIRECTORY_SEPARATOR with forward slash here 
        // to avoid issues in Windows systems
        $path    = str_replace( DIRECTORY_SEPARATOR, '/', $path);
        $abspath = str_replace( DIRECTORY_SEPARATOR, '/', ABSPATH);
        $url     = str_replace( $abspath, '', $path );

        return esc_url_raw( site_url( $url ) );
    }