Rest
in package
The rest class is used to provide raw JSON API data to the client
Table of Contents
- $data : array<string|int, mixed>
- $json : string
- __construct() : mixed
- Creates a rest object
- execute() : mixed
- Echoes the payload as pretty-printed JSON. The Content-Type is the business of the caller, see Response::generateRest().
- ShowError() : mixed
- Replaces the payload with an error object, sends it to the client and exits via execute()
Properties
$data
private
array<string|int, mixed>
$data
Payload of the rest
$json
private
string
$json
The payload formatted as json
Methods
__construct()
Creates a rest object
public
__construct(array<string|int, mixed> $data, array<string|int, string> $urlParts) : mixed
Parameters
- $data : array<string|int, mixed>
-
Payload to send; merged after the auto-generated 'meta' block (endpoint, request, timestamp), so a 'meta' key in it overwrites that block.
- $urlParts : array<string|int, string>
-
to which the request was targeted at
Return values
mixed —execute()
Echoes the payload as pretty-printed JSON. The Content-Type is the business of the caller, see Response::generateRest().
public
execute([bool $die = true ]) : mixed
Parameters
- $die : bool = true
-
Whether to call exit after echoing Text that is no UTF-8 goes out with the broken bytes replaced by U+FFFD.
Tags
Return values
mixed —ShowError()
Replaces the payload with an error object, sends it to the client and exits via execute()
public
ShowError(string|int $code, string $message) : mixed
Parameters
- $code : string|int
-
The error code
- $message : string
-
A human readable message, explaining the error