xref: /webtrees/app/Http/Middleware/CheckForMaintenanceMode.php (revision a6410500f0872b957a8d89f116e3328475633a80)
1*a6410500SGreg Roach<?php
2*a6410500SGreg Roach/**
3*a6410500SGreg Roach * webtrees: online genealogy
4*a6410500SGreg Roach * Copyright (C) 2018 webtrees development team
5*a6410500SGreg Roach * This program is free software: you can redistribute it and/or modify
6*a6410500SGreg Roach * it under the terms of the GNU General Public License as published by
7*a6410500SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8*a6410500SGreg Roach * (at your option) any later version.
9*a6410500SGreg Roach * This program is distributed in the hope that it will be useful,
10*a6410500SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*a6410500SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*a6410500SGreg Roach * GNU General Public License for more details.
13*a6410500SGreg Roach * You should have received a copy of the GNU General Public License
14*a6410500SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15*a6410500SGreg Roach */
16*a6410500SGreg Roachdeclare(strict_types=1);
17*a6410500SGreg Roach
18*a6410500SGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware;
19*a6410500SGreg Roach
20*a6410500SGreg Roachuse Closure;
21*a6410500SGreg Roachuse Symfony\Component\HttpFoundation\Request;
22*a6410500SGreg Roachuse Symfony\Component\HttpFoundation\Response;
23*a6410500SGreg Roach
24*a6410500SGreg Roach/**
25*a6410500SGreg Roach * Middleware to check whether the site is offline.
26*a6410500SGreg Roach */
27*a6410500SGreg Roachclass CheckForMaintenanceMode {
28*a6410500SGreg Roach	/**
29*a6410500SGreg Roach	 * @param Request $request
30*a6410500SGreg Roach	 * @param Closure $next
31*a6410500SGreg Roach	 *
32*a6410500SGreg Roach	 * @return Response
33*a6410500SGreg Roach	 */
34*a6410500SGreg Roach	public function handle(Request $request, Closure $next): Response {
35*a6410500SGreg Roach		$file = WT_ROOT . 'data/offline.txt';
36*a6410500SGreg Roach
37*a6410500SGreg Roach		if (file_exists($file)) {
38*a6410500SGreg Roach			$html = view('layouts/offline', [
39*a6410500SGreg Roach				'message' => file_get_contents($file),
40*a6410500SGreg Roach				'url'     => $request->getRequestUri(),
41*a6410500SGreg Roach			]);
42*a6410500SGreg Roach
43*a6410500SGreg Roach			return new Response($html, Response::HTTP_SERVICE_UNAVAILABLE);
44*a6410500SGreg Roach		}
45*a6410500SGreg Roach
46*a6410500SGreg Roach		return $next($request);
47*a6410500SGreg Roach	}
48*a6410500SGreg Roach}
49