. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\RequestMethodInterface; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Session; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use function in_array; 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 { /** @var Tree|null $tree */ $tree = app(Tree::class); // The tree exists, we have access to it, and it is fully imported. if ($tree instanceof Tree && $tree->getPreference('imported') === '1') { return redirect(route('tree-page', ['ged' => $tree->name()])); } // Not logged in? if (!Auth::check()) { return redirect(route('login', ['url' => (string) $request->getUri()])); } // No tree or tree not imported? if (Auth::isAdmin()) { return redirect(route('admin-trees')); } return $this->viewResponse('errors/no-tree-access', ['title' => '']); } }