Simplified how the not-found redirects are resolved

This commit is contained in:
Alejandro Celaya
2021-09-26 09:40:24 +02:00
parent ce7296eebb
commit 7db6136436
2 changed files with 9 additions and 15 deletions

View File

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