class JSON implements ResponseBuilderInterface

JSON builder.

Properties

protected mixed $data Data.
protected int $options JSON encode options.
protected string|null $callback Callback.
protected int|null $status Status code.
protected string|null $charset Character set.

Methods

__construct(mixed $data, int $options = 0, int|null $status = null, string|null $charset = null)

Constructor.

asJsonpWith(string $callback)

Enables JSONP support.

setStatus(int $status)

Sets the status code.

setCharset(string $charset)

Sets the status code.

string
normalizeCallback(string $callback)

Ensures a valid callback name.

build(Request $request, Response $response)

Builds the response.

Details

at line 66
__construct(mixed $data, int $options = 0, int|null $status = null, string|null $charset = null)

Constructor.

Parameters

mixed $data Data
int $options JSON encode options
int|null $status Status code
string|null $charset Character set

at line 83
JSON asJsonpWith(string $callback)

Enables JSONP support.

Parameters

string $callback Query string field

Return Value

JSON

at line 96
JSON setStatus(int $status)

Sets the status code.

Parameters

int $status Status code

Return Value

JSON

at line 109
JSON setCharset(string $charset)

Sets the status code.

Parameters

string $charset Character set

Return Value

JSON

at line 122
protected string normalizeCallback(string $callback)

Ensures a valid callback name.

Parameters

string $callback Callback name

Return Value

string

at line 135
build(Request $request, Response $response)

Builds the response.

Parameters

Request $request Request instance
Response $response Response instance