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