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 $statusCode Status code.
protected string|null $charset Character set.

Methods

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

Constructor.

asJsonpWith(string $callback)

Enables JSONP support.

setCharset(string $charset)

Sets the response character set.

string|null
getCharset()

Returns the response character set.

setStatus(int $statusCode)

Sets the HTTP status code.

int|null
getStatus()

Returns the HTTP status code.

string
normalizeCallback(string $callback)

Ensures a valid callback name.

build(Request $request, Response $response)

Builds the response.

Details

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

Constructor.

Parameters

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

at line 81
JSON asJsonpWith(string $callback)

Enables JSONP support.

Parameters

string $callback Query string field

Return Value

JSON

at line 94
JSON setCharset(string $charset)

Sets the response character set.

Parameters

string $charset Character set

Return Value

JSON

at line 106
string|null getCharset()

Returns the response character set.

Return Value

string|null

at line 117
JSON setStatus(int $statusCode)

Sets the HTTP status code.

Parameters

int $statusCode Status code

Return Value

JSON

at line 129
int|null getStatus()

Returns the HTTP status code.

Return Value

int|null

at line 140
protected string normalizeCallback(string $callback)

Ensures a valid callback name.

Parameters

string $callback Callback name

Return Value

string

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

Builds the response.

Parameters

Request $request Request instance
Response $response Response instance