xref: /webtrees/app/Http/Middleware/CheckForMaintenanceMode.php (revision 5bfc689774bb9a6401271c4ed15a6d50652c991b)
1a6410500SGreg Roach<?php
23976b470SGreg Roach
3a6410500SGreg Roach/**
4a6410500SGreg Roach * webtrees: online genealogy
5*5bfc6897SGreg Roach * Copyright (C) 2022 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
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16a6410500SGreg Roach */
17fcfa147eSGreg Roach
18a6410500SGreg Roachdeclare(strict_types=1);
19a6410500SGreg Roach
20a6410500SGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware;
21a6410500SGreg Roach
226ccdf4f0SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
23f397d0fdSGreg Roachuse Fisharebest\Webtrees\Webtrees;
246ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface;
256ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
266ccdf4f0SGreg Roachuse Psr\Http\Server\MiddlewareInterface;
276ccdf4f0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
28a6410500SGreg Roach
29a6410500SGreg Roach/**
30a6410500SGreg Roach * Middleware to check whether the site is offline.
31a6410500SGreg Roach */
32e16a1bfdSGreg Roachclass CheckForMaintenanceMode implements MiddlewareInterface, StatusCodeInterface
33c1010edaSGreg Roach{
34a6410500SGreg Roach    /**
356ccdf4f0SGreg Roach     * @param ServerRequestInterface  $request
366ccdf4f0SGreg Roach     * @param RequestHandlerInterface $handler
37a6410500SGreg Roach     *
386ccdf4f0SGreg Roach     * @return ResponseInterface
39a6410500SGreg Roach     */
406ccdf4f0SGreg Roach    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
41c1010edaSGreg Roach    {
42f397d0fdSGreg Roach        if (file_exists(Webtrees::OFFLINE_FILE)) {
43a6410500SGreg Roach            $html = view('layouts/offline', [
44f397d0fdSGreg Roach                'message' => file_get_contents(Webtrees::OFFLINE_FILE),
4509482a55SGreg Roach                'url'     => (string) $request->getUri(),
46a6410500SGreg Roach            ]);
47a6410500SGreg Roach
4871378461SGreg Roach            return response($html, StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE);
49a6410500SGreg Roach        }
50a6410500SGreg Roach
516ccdf4f0SGreg Roach        return $handler->handle($request);
52a6410500SGreg Roach    }
53a6410500SGreg Roach}
54