JsonHelper
A trait that can be used by controllers who need to return typical JSON
Instance Methods
| Returns | Signature and Description |
|---|---|
ResponseInterface | sendCreated(, , , )Send notice that an entity was created. |
ResponseInterface | sendDeleted(, , , )Send notice that objects were deleted. |
ResponseInterface | sendItems<T>(, , , )Sends a Content-Range header for pagination |
ResponseInterface | sendJson(, )Send something as JSON |
ResponseInterface | sendUpdated(, , , )Send notice that objects were updated. |
ResponseInterface | sendVerb(, , , , )Sends a generic notice that objects have been operated on |
Method Details
sendCreated
sendCreated(ResponseInterface $response, string $type, ConstVector<string> $ids, ConstMap<string,mixed> $extra = ImmMap{})Send notice that an entity was created.
| Name | Type | Description |
|---|---|---|
$response | ResponseInterface | The response |
$type | string | The entity type |
$ids | ConstVector<string> | |
$extra | ConstMap<string,mixed> |
| Type | Description |
|---|---|
ResponseInterface | The JSON response |
sendDeleted
sendDeleted(ResponseInterface $response, string $type, ConstVector<string> $ids, ConstMap<string,mixed> $extra = ImmMap{})Send notice that objects were deleted.
| Name | Type | Description |
|---|---|---|
$response | ResponseInterface | The response |
$type | string | The entity type |
$ids | ConstVector<string> | The entity ids |
$extra | ConstMap<string,mixed> |
| Type | Description |
|---|---|
ResponseInterface | The JSON response |
sendItems
sendItems<T>(ResponseInterface $response, Traversable<T> $items, ?Pagination $pagination = null, ?int $total = null)Sends a Content-Range header for pagination
- Since
- 0.6.0
| Name | Type | Description |
|---|---|---|
$response | ResponseInterface | The response |
$items | Traversable<T> | |
$pagination | ?Pagination | |
$total | ?int |
| Type | Description |
|---|---|
ResponseInterface | The JSON response |
sendJson
sendJson(ResponseInterface $response, mixed $payload)Send something as JSON
| Name | Type | Description |
|---|---|---|
$response | ResponseInterface | The response |
$payload | mixed | The object to serialize |
| Type | Description |
|---|---|
ResponseInterface | The JSON response |
sendUpdated
sendUpdated(ResponseInterface $response, string $type, ConstVector<string> $ids, ConstMap<string,mixed> $extra = ImmMap{})Send notice that objects were updated.
| Name | Type | Description |
|---|---|---|
$response | ResponseInterface | The response |
$type | string | The entity type |
$ids | ConstVector<string> | The entity ids |
$extra | ConstMap<string,mixed> | Any extra data to serialize |
| Type | Description |
|---|---|
ResponseInterface | The JSON response |
sendVerb
sendVerb(string $verb, ResponseInterface $response, string $type, ConstVector<string> $ids, ConstMap<string,mixed> $extra = ImmMap{})Sends a generic notice that objects have been operated on
| Name | Type | Description |
|---|---|---|
$verb | string | The verb |
$response | ResponseInterface | The response |
$type | string | The entity type |
$ids | ConstVector<string> | The entity ids |
$extra | ConstMap<string,mixed> | Any extra data to serialize |
| Type | Description |
|---|---|
ResponseInterface | The JSON response |