-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPingRequestHandler.php
More file actions
34 lines (26 loc) · 995 Bytes
/
PingRequestHandler.php
File metadata and controls
34 lines (26 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
namespace App\Core\RequestHandler;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
final class PingRequestHandler implements RequestHandlerInterface
{
public function __construct(
private readonly ResponseFactoryInterface $responseFactory,
) {}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$response = $this->responseFactory->createResponse(200)
->withHeader('Content-Type', 'application/json')
->withHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
->withHeader('Pragma', 'no-cache')
->withHeader('Expires', '0')
;
/** @var non-empty-string $json */
$json = json_encode(['datetime' => date('c')]);
$response->getBody()->write($json);
return $response;
}
}