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

Breadcrumb

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

function UrlHelper::getAbsoluteUrl

File

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

Class

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

Namespace

Symfony\Component\HttpFoundation

Code

public function getAbsoluteUrl(string $path) : string {
    if (str_contains($path, '://') || str_starts_with($path, '//')) {
        return $path;
    }
    if (null === ($request = $this->requestStack
        ->getMainRequest())) {
        return $this->getAbsoluteUrlFromContext($path);
    }
    if ('#' === $path[0]) {
        $path = $request->getRequestUri() . $path;
    }
    elseif ('?' === $path[0]) {
        $path = $request->getPathInfo() . $path;
    }
    if (!$path || '/' !== $path[0]) {
        $prefix = $request->getPathInfo();
        $last = \strlen($prefix) - 1;
        if ($last !== ($pos = strrpos($prefix, '/'))) {
            $prefix = substr($prefix, 0, $pos) . '/';
        }
        return $request->getUriForPath($prefix . $path);
    }
    return $request->getSchemeAndHttpHost() . $path;
}

API Navigation

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