1efe93098SGreg Roach<?php 23976b470SGreg Roach 3efe93098SGreg Roach/** 4efe93098SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16efe93098SGreg Roach */ 17fcfa147eSGreg Roach 18efe93098SGreg Roachdeclare(strict_types=1); 19efe93098SGreg Roach 20efe93098SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21efe93098SGreg Roach 22efe93098SGreg Roachuse Fisharebest\Webtrees\Services\ServerCheckService; 23efe93098SGreg Roachuse Psr\Http\Message\ResponseInterface; 24efe93098SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 25efe93098SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 263976b470SGreg Roach 27efe93098SGreg Roachuse function response; 28efe93098SGreg Roach 29efe93098SGreg Roach/** 30efe93098SGreg Roach * Check the server is up. 31efe93098SGreg Roach */ 32efe93098SGreg Roachclass Ping implements RequestHandlerInterface 33efe93098SGreg Roach{ 34c4943cffSGreg Roach private ServerCheckService $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