slovocast/app/src/Handler/HealthCheck.php

35 lines
918 B
PHP

<?php
namespace Slovocast\Handler;
use Odan\Session\SessionInterface;
use Slovocast\Handler\Handler;
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
use Psr\Http\Message\ResponseInterface as Response;
class HealthCheck extends Handler
{
public function __construct(
protected DatabaseHandlerInterface $database,
protected SessionInterface $session
) { }
public function handle(): Response
{
$statement = $this->database->getConnection()->query('SELECT 1');
$results = $statement->fetchAll();
if (!$this->session->has("healthcheck")) {
$this->session->set("healthcheck", true);
}
$activeSession = $this->session->get("healthcheck");
return $this->json([
'http' => true,
'database' => (bool) count($results),
'active_session' => $activeSession,
]);
}
}