<?php
declare(strict_types=1);
namespace App\Controller;
use App\Helper\JsonResponse;
use Pimple\Psr11\Container;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
final class Home
{
private const API_NAME = 'slim4-api-skeleton';
private const API_VERSION = '0.22.0';
private $container;
public function __construct(Container $container)
{
$this->container = $container;
}
public function getHelp(Request $request, Response $response): Response
{
$message = [
'api' => self::API_NAME,
'version' => self::API_VERSION,
'timestamp' => time(),
];
return JsonResponse::withJson($response, json_encode($message), 200);
}
public function getStatus(Request $request, Response $response): Response
{
$this->container->get('db');
$status = [
'status' => [
'database' => 'OK',
],
'api' => self::API_NAME,
'version' => self::API_VERSION,
'timestamp' => time(),
];
return JsonResponse::withJson($response, json_encode($status), 200);
}
}