xref: /webtrees/app/Http/RequestHandlers/Ping.php (revision efe93098cb9072f1f0ff59553700962867f55406)
1*efe93098SGreg Roach<?php
2*efe93098SGreg Roach/**
3*efe93098SGreg Roach * webtrees: online genealogy
4*efe93098SGreg Roach * Copyright (C) 2019 webtrees development team
5*efe93098SGreg Roach * This program is free software: you can redistribute it and/or modify
6*efe93098SGreg Roach * it under the terms of the GNU General Public License as published by
7*efe93098SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8*efe93098SGreg Roach * (at your option) any later version.
9*efe93098SGreg Roach * This program is distributed in the hope that it will be useful,
10*efe93098SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*efe93098SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*efe93098SGreg Roach * GNU General Public License for more details.
13*efe93098SGreg Roach * You should have received a copy of the GNU General Public License
14*efe93098SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15*efe93098SGreg Roach */
16*efe93098SGreg Roachdeclare(strict_types=1);
17*efe93098SGreg Roach
18*efe93098SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
19*efe93098SGreg Roach
20*efe93098SGreg Roachuse Fisharebest\Webtrees\Services\ServerCheckService;
21*efe93098SGreg Roachuse Psr\Http\Message\ResponseInterface;
22*efe93098SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
23*efe93098SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
24*efe93098SGreg Roachuse function response;
25*efe93098SGreg Roach
26*efe93098SGreg Roach/**
27*efe93098SGreg Roach * Check the server is up.
28*efe93098SGreg Roach */
29*efe93098SGreg Roachclass Ping implements RequestHandlerInterface
30*efe93098SGreg Roach{
31*efe93098SGreg Roach    /** @var ServerCheckService */
32*efe93098SGreg Roach    private $server_check_service;
33*efe93098SGreg Roach
34*efe93098SGreg Roach    /**
35*efe93098SGreg Roach     * @param ServerCheckService $server_check_service
36*efe93098SGreg Roach     */
37*efe93098SGreg Roach    public function __construct(ServerCheckService $server_check_service)
38*efe93098SGreg Roach    {
39*efe93098SGreg Roach        $this->server_check_service = $server_check_service;
40*efe93098SGreg Roach    }
41*efe93098SGreg Roach
42*efe93098SGreg Roach    /**
43*efe93098SGreg Roach     * @param ServerRequestInterface $request
44*efe93098SGreg Roach     *
45*efe93098SGreg Roach     * @return ResponseInterface
46*efe93098SGreg Roach     */
47*efe93098SGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
48*efe93098SGreg Roach    {
49*efe93098SGreg Roach        if ($this->server_check_service->serverErrors()->isNotEmpty()) {
50*efe93098SGreg Roach            return response('ERROR');
51*efe93098SGreg Roach        }
52*efe93098SGreg Roach
53*efe93098SGreg Roach        if ($this->server_check_service->serverWarnings()->isNotEmpty()) {
54*efe93098SGreg Roach            return response('WARNING');
55*efe93098SGreg Roach        }
56*efe93098SGreg Roach
57*efe93098SGreg Roach        return response('OK');
58*efe93098SGreg Roach    }
59*efe93098SGreg Roach}
60