. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Webtrees; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; /** * Middleware to check whether the site is offline. */ class CheckForMaintenanceMode implements MiddlewareInterface { /** * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { if (file_exists(Webtrees::OFFLINE_FILE)) { $html = view('layouts/offline', [ 'message' => file_get_contents(Webtrees::OFFLINE_FILE), 'url' => $request->getUri(), ]); return response($html, StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE); } return $handler->handle($request); } }