JsonResponse
trait JsonResponse
A trait that support operations related to APIs and their associated JSON responses.
Properties
| static string|null | $rawInputOverride | Raw JSON override for tests |
|
| static bool | $testing | When true, do not send headers or exit; just echo JSON and return. |
|
| static int | $lastStatus | Captured status for tests (optional convenience). |
|
| static array | $lastHeaders | Captured headers for tests (optional convenience). |
Methods
Checks if CSRF token has been tampered with.
Supports operations related to handling POST and GET requests.
Makes JSON Response for error payloads.
Returns json response success = true and sets path for redirect.
Sends a JSON response with headers and status code.
Respond to CORS preflight.
Inject JSON body by providing payload parameter. Also performs cleanup to avoid leaking into other tests.
Details
at line 47
bool
apiCsrfCheck()
Checks if CSRF token has been tampered with.
at line 62
array|string
get(string|null $input = null)
Supports operations related to handling POST and GET requests.
Similar in behavior to the get function from the Input class but for JSON related operations.
at line 97
void
jsonError(string $message, int $status = 400, array $errors = [])
Makes JSON Response for error payloads.
at line 110
void
jsonRedirect(string $url)
Returns json response success = true and sets path for redirect.
at line 125
void
jsonResponse(mixed $data, int $status = 200, array $extraHeaders = [])
Sends a JSON response with headers and status code.
at line 174
void
preflight()
Respond to CORS preflight.
at line 190
static void
setRawInputOverride(mixed $payload = null)
Inject JSON body by providing payload parameter. Also performs cleanup to avoid leaking into other tests.