JSON
JSON
JSON response class.
class JSON extends \Hazaar\Controller\Response\Response implements \ArrayAccessThis response serializes arbitrary application data into JSON for HTTP clients. It supports array/object style mutation, optional JSONP callback wrapping, and direct pass-through when pre-encoded valid JSON strings are provided.
Properties
jsonContent
Raw response payload prior to JSON serialization.
protected mixed $jsonContentMay contain arrays, objects, scalar values, or pre-encoded JSON strings.
callback
public string $callbackMethods
__construct
public __construct(mixed $data, int $status = 200): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | |
$status | int |
__set
Magic setter proxy for payload key assignment.
public __set(string $key, null $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | payload key to set |
$value | null | scalar value to assign |
toArray
public toArray(): void__get
Magic getter proxy for payload key retrieval.
public __get(string $key): mixedReturns a reference to the resolved value when possible.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | payload key to read |
get
Retrieve a payload value by key.
public get(string $key): mixedSupports array-like and object-like payload containers. A null reference is returned when the key cannot be resolved.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | payload key to read |
set
Set a payload value by key.
public set(string $key, mixed $value): voidUpdates array-like or object-like payload containers in place.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | payload key to write |
$value | mixed | value to assign |
populate
public populate(array $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | array |
push
public push(array $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | array |
setCallback
Set the JSONP callback function name.
public setCallback(string $callback): voidParameters
| Parameter | Type | Description |
|---|---|---|
$callback | string | javaScript callback identifier |
content
Set the response payload.
public content(mixed $data): selfParameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | data to be serialized as JSON |
getContent
Get the final response content as JSON (or JSONP).
public getContent(): stringIf the payload is already a valid JSON string, it is reused as-is; otherwise the payload is encoded with framework defaults.
hasContent
public hasContent(): booloffsetExists
public offsetExists(mixed $offset): boolParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetGet
public offsetGet(mixed $offset): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetSet
public offsetSet(mixed $offset, mixed $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed |
offsetUnset
public offsetUnset(mixed $offset): voidParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000