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

Breadcrumb

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

function UrlHelper::getAbsoluteUrlFromContext

1 call to UrlHelper::getAbsoluteUrlFromContext()
UrlHelper::getAbsoluteUrl in vendor/symfony/http-foundation/UrlHelper.php

File

vendor/symfony/http-foundation/UrlHelper.php, line 72

Class

UrlHelper
A helper service for manipulating URLs within and outside the request scope.

Namespace

Symfony\Component\HttpFoundation

Code

private function getAbsoluteUrlFromContext(string $path) : string {
    if (null === ($context = $this->requestContext)) {
        return $path;
    }
    if ($context instanceof RequestContextAwareInterface) {
        $context = $context->getContext();
    }
    if ('' === ($host = $context->getHost())) {
        return $path;
    }
    $scheme = $context->getScheme();
    $port = '';
    if ('http' === $scheme && 80 !== $context->getHttpPort()) {
        $port = ':' . $context->getHttpPort();
    }
    elseif ('https' === $scheme && 443 !== $context->getHttpsPort()) {
        $port = ':' . $context->getHttpsPort();
    }
    if ('#' === $path[0]) {
        $queryString = $context->getQueryString();
        $path = $context->getPathInfo() . ($queryString ? '?' . $queryString : '') . $path;
    }
    elseif ('?' === $path[0]) {
        $path = $context->getPathInfo() . $path;
    }
    if ('/' !== $path[0]) {
        $path = rtrim($context->getBaseUrl(), '/') . '/' . $path;
    }
    return $scheme . '://' . $host . $port . $path;
}

API Navigation

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