1a6410500SGreg Roach<?php 2a6410500SGreg Roach/** 3a6410500SGreg Roach * webtrees: online genealogy 4a6410500SGreg Roach * Copyright (C) 2018 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 20a6410500SGreg Roachuse Closure; 21a6410500SGreg Roachuse Symfony\Component\HttpFoundation\Request; 22a6410500SGreg Roachuse Symfony\Component\HttpFoundation\Response; 23a6410500SGreg Roach 24a6410500SGreg Roach/** 25a6410500SGreg Roach * Middleware to check whether the site is offline. 26a6410500SGreg Roach */ 27*c1010edaSGreg Roachclass CheckForMaintenanceMode implements MiddlewareInterface 28*c1010edaSGreg Roach{ 29a6410500SGreg Roach /** 30a6410500SGreg Roach * @param Request $request 31a6410500SGreg Roach * @param Closure $next 32a6410500SGreg Roach * 33a6410500SGreg Roach * @return Response 34a6410500SGreg Roach */ 35*c1010edaSGreg Roach public function handle(Request $request, Closure $next): Response 36*c1010edaSGreg Roach { 37a6410500SGreg Roach $file = WT_ROOT . 'data/offline.txt'; 38a6410500SGreg Roach 39a6410500SGreg Roach if (file_exists($file)) { 40a6410500SGreg Roach $html = view('layouts/offline', [ 41a6410500SGreg Roach 'message' => file_get_contents($file), 42a6410500SGreg Roach 'url' => $request->getRequestUri(), 43a6410500SGreg Roach ]); 44a6410500SGreg Roach 45a6410500SGreg Roach return new Response($html, Response::HTTP_SERVICE_UNAVAILABLE); 46a6410500SGreg Roach } 47a6410500SGreg Roach 48a6410500SGreg Roach return $next($request); 49a6410500SGreg Roach } 50a6410500SGreg Roach} 51