Fixed the way ShortUrlIdentifier is created from requests, on different request scopes

This commit is contained in:
Alejandro Celaya 2020-02-01 12:54:10 +01:00
parent 327d35fe57
commit fd82de31c0
4 changed files with 13 additions and 5 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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');

View file

@ -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));
}