Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractBrowser.php

function AbstractBrowser::getAbsoluteUri

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

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

File

vendor/symfony/browser-kit/AbstractBrowser.php, line 628

Class

AbstractBrowser
Simulates a browser.

Namespace

Symfony\Component\BrowserKit

Code

protected function getAbsoluteUri(string $uri) : string {
    // already absolute?
    if (str_starts_with($uri, 'http://') || str_starts_with($uri, 'https://')) {
        return $uri;
    }
    if (!$this->history
        ->isEmpty()) {
        $currentUri = $this->history
            ->current()
            ->getUri();
    }
    else {
        $currentUri = \sprintf('http%s://%s/', isset($this->server['HTTPS']) ? 's' : '', $this->server['HTTP_HOST'] ?? 'localhost');
    }
    // protocol relative URL
    if ('' !== trim($uri, '/') && str_starts_with($uri, '//')) {
        return parse_url($currentUri, \PHP_URL_SCHEME) . ':' . $uri;
    }
    // anchor or query string parameters?
    if (!$uri || '#' === $uri[0] || '?' === $uri[0]) {
        return preg_replace('/[#?].*?$/', '', $currentUri) . $uri;
    }
    if ('/' !== $uri[0]) {
        $path = parse_url($currentUri, \PHP_URL_PATH);
        if (!str_ends_with($path, '/')) {
            $path = substr($path, 0, strrpos($path, '/') + 1);
        }
        $uri = $path . $uri;
    }
    return preg_replace('#^(.*?//[^/]+)\\/.*$#', '$1', $currentUri) . $uri;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal