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