. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\RequestMethodInterface; use Fisharebest\Webtrees\Exceptions\HttpNotFoundException; 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 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 HttpNotFoundException(); } return redirect(route(HomePage::class)); } }