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 20*6ccdf4f0SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 21*6ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 22*6ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 23*6ccdf4f0SGreg Roachuse Psr\Http\Server\MiddlewareInterface; 24*6ccdf4f0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 25a6410500SGreg Roach 26a6410500SGreg Roach/** 27a6410500SGreg Roach * Middleware to check whether the site is offline. 28a6410500SGreg Roach */ 29c1010edaSGreg Roachclass CheckForMaintenanceMode implements MiddlewareInterface 30c1010edaSGreg Roach{ 31a6410500SGreg Roach /** 32*6ccdf4f0SGreg Roach * @param ServerRequestInterface $request 33*6ccdf4f0SGreg Roach * @param RequestHandlerInterface $handler 34a6410500SGreg Roach * 35*6ccdf4f0SGreg Roach * @return ResponseInterface 36a6410500SGreg Roach */ 37*6ccdf4f0SGreg Roach public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 38c1010edaSGreg Roach { 39a6410500SGreg Roach $file = WT_ROOT . 'data/offline.txt'; 40a6410500SGreg Roach 41a6410500SGreg Roach if (file_exists($file)) { 42a6410500SGreg Roach $html = view('layouts/offline', [ 43a6410500SGreg Roach 'message' => file_get_contents($file), 44*6ccdf4f0SGreg Roach 'url' => $request->getUri(), 45a6410500SGreg Roach ]); 46a6410500SGreg Roach 47*6ccdf4f0SGreg Roach return response($html, StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE); 48a6410500SGreg Roach } 49a6410500SGreg Roach 50*6ccdf4f0SGreg Roach return $handler->handle($request); 51a6410500SGreg Roach } 52a6410500SGreg Roach} 53