1efe93098SGreg Roach<?php 23976b470SGreg Roach 3efe93098SGreg Roach/** 4efe93098SGreg Roach * webtrees: online genealogy 5*89f7189bSGreg Roach * Copyright (C) 2021 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 15*89f7189bSGreg 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{ 34efe93098SGreg Roach /** @var ServerCheckService */ 35efe93098SGreg Roach private $server_check_service; 36efe93098SGreg Roach 37efe93098SGreg Roach /** 38efe93098SGreg Roach * @param ServerCheckService $server_check_service 39efe93098SGreg Roach */ 40efe93098SGreg Roach public function __construct(ServerCheckService $server_check_service) 41efe93098SGreg Roach { 42efe93098SGreg Roach $this->server_check_service = $server_check_service; 43efe93098SGreg Roach } 44efe93098SGreg Roach 45efe93098SGreg Roach /** 46efe93098SGreg Roach * @param ServerRequestInterface $request 47efe93098SGreg Roach * 48efe93098SGreg Roach * @return ResponseInterface 49efe93098SGreg Roach */ 50efe93098SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 51efe93098SGreg Roach { 52efe93098SGreg Roach if ($this->server_check_service->serverErrors()->isNotEmpty()) { 53efe93098SGreg Roach return response('ERROR'); 54efe93098SGreg Roach } 55efe93098SGreg Roach 56efe93098SGreg Roach if ($this->server_check_service->serverWarnings()->isNotEmpty()) { 57efe93098SGreg Roach return response('WARNING'); 58efe93098SGreg Roach } 59efe93098SGreg Roach 60efe93098SGreg Roach return response('OK'); 61efe93098SGreg Roach } 62efe93098SGreg Roach} 63