diff --git a/module/Core/src/Action/AbstractTrackingAction.php b/module/Core/src/Action/AbstractTrackingAction.php index 3655bd32..ae5e6fb6 100644 --- a/module/Core/src/Action/AbstractTrackingAction.php +++ b/module/Core/src/Action/AbstractTrackingAction.php @@ -45,8 +45,8 @@ abstract class AbstractTrackingAction implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $shortCode = $request->getAttribute('shortCode', ''); - $identifier = ShortUrlIdentifier::fromRequest($request); + $identifier = ShortUrlIdentifier::fromRedirectRequest($request); + $shortCode = $identifier->shortCode(); $query = $request->getQueryParams(); $disableTrackParam = $this->appOptions->getDisableTrackParam(); diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index df06edbd..7a07f2a1 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -39,7 +39,7 @@ class QrCodeAction implements MiddlewareInterface public function process(Request $request, RequestHandlerInterface $handler): Response { - $identifier = ShortUrlIdentifier::fromRequest($request); + $identifier = ShortUrlIdentifier::fromRedirectRequest($request); try { $this->urlResolver->resolveEnabledShortUrl($identifier); diff --git a/module/Core/src/Model/ShortUrlIdentifier.php b/module/Core/src/Model/ShortUrlIdentifier.php index dae3a15b..820bcf03 100644 --- a/module/Core/src/Model/ShortUrlIdentifier.php +++ b/module/Core/src/Model/ShortUrlIdentifier.php @@ -18,7 +18,7 @@ final class ShortUrlIdentifier $this->domain = $domain; } - public static function fromRequest(ServerRequestInterface $request): self + public static function fromApiRequest(ServerRequestInterface $request): self { $shortCode = $request->getAttribute('shortCode', ''); $domain = $request->getQueryParams()['domain'] ?? null; @@ -26,6 +26,14 @@ final class ShortUrlIdentifier return new self($shortCode, $domain); } + public static function fromRedirectRequest(ServerRequestInterface $request): self + { + $shortCode = $request->getAttribute('shortCode', ''); + $domain = $request->getUri()->getAuthority(); + + return new self($shortCode, $domain); + } + public static function fromCli(InputInterface $input): self { $shortCode = $input->getArgument('shortCode'); diff --git a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php index bf31805d..41cd2b2d 100644 --- a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php @@ -34,7 +34,7 @@ class ResolveShortUrlAction extends AbstractRestAction public function handle(Request $request): Response { $transformer = new ShortUrlDataTransformer($this->domainConfig); - $url = $this->urlResolver->resolveShortUrl(ShortUrlIdentifier::fromRequest($request)); + $url = $this->urlResolver->resolveShortUrl(ShortUrlIdentifier::fromApiRequest($request)); return new JsonResponse($transformer->transform($url)); }