false, 'error'=>'auth_required'], 401); } if ($roles) { $role = strtolower((string)($_SESSION['role'] ?? '')); $allowed = array_map(fn($r)=>strtolower((string)$r), $roles); if (!in_array($role, $allowed, true)) { json_response(['ok'=>false, 'error'=>'forbidden'], 403); } } } function read_json_body(): array { $raw = file_get_contents('php://input'); if (!$raw) return []; $data = json_decode($raw, true); return is_array($data) ? $data : []; }