25 lines
763 B
PHP
25 lines
763 B
PHP
<?php
|
|
// ─── SunScope — JSON response helpers ────────────────────────────────────
|
|
|
|
function json_out(array $data, int $status = 200): void {
|
|
http_response_code($status);
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
exit;
|
|
}
|
|
|
|
function json_error(string $message, int $status = 400): void {
|
|
json_out(['ok' => false, 'error' => $message], $status);
|
|
}
|
|
|
|
function json_body(): array {
|
|
$body = json_decode(file_get_contents('php://input'), true);
|
|
return is_array($body) ? $body : [];
|
|
}
|
|
|
|
function require_method(string $method): void {
|
|
if ($_SERVER['REQUEST_METHOD'] !== $method) {
|
|
json_error('Method not allowed', 405);
|
|
}
|
|
}
|