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\HttpFoundationCode
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;
}