1a6410500SGreg Roach<?php 2a6410500SGreg Roach/** 3a6410500SGreg Roach * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 5a6410500SGreg Roach * This program is free software: you can redistribute it and/or modify 6a6410500SGreg Roach * it under the terms of the GNU General Public License as published by 7a6410500SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8a6410500SGreg Roach * (at your option) any later version. 9a6410500SGreg Roach * This program is distributed in the hope that it will be useful, 10a6410500SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a6410500SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a6410500SGreg Roach * GNU General Public License for more details. 13a6410500SGreg Roach * You should have received a copy of the GNU General Public License 14a6410500SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15a6410500SGreg Roach */ 16a6410500SGreg Roachdeclare(strict_types=1); 17a6410500SGreg Roach 18a6410500SGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware; 19a6410500SGreg Roach 206ccdf4f0SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 21*f397d0fdSGreg Roachuse Fisharebest\Webtrees\Webtrees; 226ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 236ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 246ccdf4f0SGreg Roachuse Psr\Http\Server\MiddlewareInterface; 256ccdf4f0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 26a6410500SGreg Roach 27a6410500SGreg Roach/** 28a6410500SGreg Roach * Middleware to check whether the site is offline. 29a6410500SGreg Roach */ 30c1010edaSGreg Roachclass CheckForMaintenanceMode implements MiddlewareInterface 31c1010edaSGreg Roach{ 32a6410500SGreg Roach /** 336ccdf4f0SGreg Roach * @param ServerRequestInterface $request 346ccdf4f0SGreg Roach * @param RequestHandlerInterface $handler 35a6410500SGreg Roach * 366ccdf4f0SGreg Roach * @return ResponseInterface 37a6410500SGreg Roach */ 386ccdf4f0SGreg Roach public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 39c1010edaSGreg Roach { 40*f397d0fdSGreg Roach if (file_exists(Webtrees::OFFLINE_FILE)) { 41a6410500SGreg Roach $html = view('layouts/offline', [ 42*f397d0fdSGreg Roach 'message' => file_get_contents(Webtrees::OFFLINE_FILE), 436ccdf4f0SGreg Roach 'url' => $request->getUri(), 44a6410500SGreg Roach ]); 45a6410500SGreg Roach 466ccdf4f0SGreg Roach return response($html, StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE); 47a6410500SGreg Roach } 48a6410500SGreg Roach 496ccdf4f0SGreg Roach return $handler->handle($request); 50a6410500SGreg Roach } 51a6410500SGreg Roach} 52