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