throw new \TypeError(__METHOD__.': Argument #2 ($requestContext) must of type Symfony\Component\Routing\RequestContextAwareInterface|Symfony\Component\Routing\RequestContext|null, '.get_debug_type($requestContext).' given.');
}
$this->requestStack = $requestStack;
$this->requestContext = $requestContext;
}
public function getAbsoluteUrl(string $path): string
{
if (str_contains($path, '://') || '//' === substr($path, 0, 2)) {
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;
}
public function getRelativePath(string $path): string
{
if (str_contains($path, '://') || '//' === substr($path, 0, 2)) {
return $path;
}
if (null === $request = $this->requestStack->getMainRequest()) {
return $path;
}
return $request->getRelativeUriForPath($path);
}
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()) {