mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-16 18:24:56 -06:00
Simplified how the not-found redirects are resolved
This commit is contained in:
parent
ce7296eebb
commit
7db6136436
@ -27,16 +27,9 @@ class NotFoundRedirectHandler implements MiddlewareInterface
|
||||
/** @var NotFoundType $notFoundType */
|
||||
$notFoundType = $request->getAttribute(NotFoundType::class);
|
||||
$authority = $request->getUri()->getAuthority();
|
||||
$domainSpecificRedirect = $this->resolveDomainSpecificRedirect($authority, $notFoundType);
|
||||
$redirectConfig = $this->domainService->findByAuthority($authority) ?? $this->redirectOptions;
|
||||
$redirectResponse = $this->redirectResolver->resolveRedirectResponse($notFoundType, $redirectConfig);
|
||||
|
||||
return $domainSpecificRedirect
|
||||
?? $this->redirectResolver->resolveRedirectResponse($notFoundType, $this->redirectOptions)
|
||||
?? $handler->handle($request);
|
||||
}
|
||||
|
||||
private function resolveDomainSpecificRedirect(string $authority, NotFoundType $notFoundType): ?ResponseInterface
|
||||
{
|
||||
$domain = $this->domainService->findByAuthority($authority);
|
||||
return $domain === null ? null : $this->redirectResolver->resolveRedirectResponse($notFoundType, $domain);
|
||||
return $redirectResponse ?? $handler->handle($request);
|
||||
}
|
||||
}
|
||||
|
@ -72,17 +72,18 @@ class NotFoundRedirectHandlerTest extends TestCase
|
||||
$domainService->findByAuthority(Argument::cetera())
|
||||
->willReturn(null)
|
||||
->shouldBeCalledOnce();
|
||||
$resolver->resolveRedirectResponse(Argument::cetera())
|
||||
->willReturn(null)
|
||||
->shouldBeCalledOnce();
|
||||
$resolver->resolveRedirectResponse(
|
||||
Argument::type(NotFoundType::class),
|
||||
Argument::type(NotFoundRedirectOptions::class),
|
||||
)->willReturn(null)->shouldBeCalledOnce();
|
||||
}];
|
||||
yield 'non-redirecting domain' => [function (ObjectProphecy $domainService, ObjectProphecy $resolver): void {
|
||||
$domainService->findByAuthority(Argument::cetera())
|
||||
->willReturn(Domain::withAuthority(''))
|
||||
->shouldBeCalledOnce();
|
||||
$resolver->resolveRedirectResponse(Argument::cetera())
|
||||
$resolver->resolveRedirectResponse(Argument::type(NotFoundType::class), Argument::type(Domain::class))
|
||||
->willReturn(null)
|
||||
->shouldBeCalledTimes(2);
|
||||
->shouldBeCalledOnce();
|
||||
}];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user