You are here

protected function Client::getAbsoluteUri in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/browser-kit/Client.php \Symfony\Component\BrowserKit\Client::getAbsoluteUri()

Takes a URI and converts it to absolute if it is not already absolute.

Parameters

string $uri A URI:

Return value

string An absolute URI

1 call to Client::getAbsoluteUri()
Client::request in vendor/symfony/browser-kit/Client.php
Calls a URI.

File

vendor/symfony/browser-kit/Client.php, line 506

Class

Client
Client simulates a browser.

Namespace

Symfony\Component\BrowserKit

Code

protected function getAbsoluteUri($uri) {

  // already absolute?
  if (0 === strpos($uri, 'http://') || 0 === strpos($uri, 'https://')) {
    return $uri;
  }
  if (!$this->history
    ->isEmpty()) {
    $currentUri = $this->history
      ->current()
      ->getUri();
  }
  else {
    $currentUri = sprintf('http%s://%s/', isset($this->server['HTTPS']) ? 's' : '', isset($this->server['HTTP_HOST']) ? $this->server['HTTP_HOST'] : 'localhost');
  }

  // protocol relative URL
  if (0 === strpos($uri, '//')) {
    return parse_url($currentUri, PHP_URL_SCHEME) . ':' . $uri;
  }

  // anchor?
  if (!$uri || '#' == $uri[0]) {
    return preg_replace('/#.*?$/', '', $currentUri) . $uri;
  }
  if ('/' !== $uri[0]) {
    $path = parse_url($currentUri, PHP_URL_PATH);
    if ('/' !== substr($path, -1)) {
      $path = substr($path, 0, strrpos($path, '/') + 1);
    }
    $uri = $path . $uri;
  }
  return preg_replace('#^(.*?//[^/]+)\\/.*$#', '$1', $currentUri) . $uri;
}