. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\RequestMethodInterface; use Fisharebest\Webtrees\Http\RequestHandlers\HomePage; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use function redirect; use function route; /** * Middleware to generate a response when no route was matched. */ class NoRouteFound implements MiddlewareInterface { use ViewResponseTrait; /** * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { if ($request->getMethod() !== RequestMethodInterface::METHOD_GET) { throw new NotFoundHttpException(); } return redirect(route(HomePage::class)); } }