26 lines
608 B
PHP
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.']);
|
|
}
|
|
}
|
|
}
|