pour prod
This commit is contained in:
25
app/Core/Request.php
Normal file
25
app/Core/Request.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user