public static function Url::buildUrl

Build a URL from parse_url parts. The generated URL will be a relative URL if a scheme or host are not provided.

Parameters

array $parts Array of parse_url parts:

Return value

string

1 call to Url::buildUrl()
Url::__toString in drupal/core/vendor/guzzle/http/Guzzle/Http/Url.php
Returns the URL as a URL string

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Url.php, line 54

Class

Url
Parses and generates URLs based on URL parts. In favor of performance, URL parts are not validated.

Namespace

Guzzle\Http

Code

public static function buildUrl(array $parts) {
  $url = $scheme = '';
  if (isset($parts['scheme'])) {
    $scheme = $parts['scheme'];
    $url .= $scheme . '://';
  }
  if (isset($parts['host'])) {
    if (isset($parts['user'])) {
      $url .= $parts['user'];
      if (isset($parts['pass'])) {
        $url .= ':' . $parts['pass'];
      }
      $url .= '@';
    }
    $url .= $parts['host'];

    // Only include the port if it is not the default port of the scheme
    if (isset($parts['port']) && !($scheme == 'http' && $parts['port'] == 80 || $scheme == 'https' && $parts['port'] == 443)) {
      $url .= ':' . $parts['port'];
    }
  }
  if (empty($parts['path'])) {
    $url .= '/';
  }
  else {
    if ($parts['path'][0] != '/') {
      $url .= '/';
    }
    $url .= $parts['path'];
  }

  // Add the query string if present
  if (!empty($parts['query'])) {
    if ($parts['query'][0] != '?') {
      $url .= array_key_exists('query_prefix', $parts) ? $parts['query_prefix'] : '?';
    }
    $url .= $parts['query'];
  }

  // Ensure that # is only added to the url if fragment contains anything.
  if (isset($parts['fragment']) && !empty($parts['fragment'])) {
    $url .= '#' . $parts['fragment'];
  }
  return $url;
}