Files
pta/app/Core/Request.php
Loic Masi 5fbf76868f pour prod
2026-08-07 16:13:43 +02:00

26 lines
608 B
PHP

<?php
declare(strict_types=1);
namespace App\Core;
final class Request
{
public static function json(): array
{
$payload = json_decode((string) file_get_contents('php://input'), true);
if (!is_array($payload)) {
JsonResponse::send(400, ['error' => 'Corps JSON invalide.']);
}
return $payload;
}
public static function requireMethod(string $method): void
{
if (strtoupper($_SERVER['REQUEST_METHOD'] ?? 'GET') !== strtoupper($method)) {
JsonResponse::send(405, ['error' => 'Méthode non autorisée.']);
}
}
}