Oihana PHP System

JsonTrait

Provides utility methods for managing JSON encoding options and creating standardized JSON HTTP responses within controllers.

This trait is designed to:

  • Initialize and manage JSON encoding flags.
  • Build PSR-7 JSON responses with proper headers.

Table of Contents

Properties

$jsonOptions  : int
The default json options used in the controller.

Methods

initializeJsonOptions()  : static
Initialize the internal $jsonOptions property.
jsonResponse()  : ResponseInterface
Return a JSON response

Properties

$jsonOptions

The default json options used in the controller.

protected int $jsonOptions = \oihana\enums\JsonParam::JSON_NONE

Methods

initializeJsonOptions()

Initialize the internal $jsonOptions property.

public initializeJsonOptions([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static
Parameters
$init : array<string|int, mixed> = []
$container : ContainerInterface|null = null
Tags
throws
ContainerExceptionInterface
throws
NotFoundExceptionInterface
Return values
static

jsonResponse()

Return a JSON response

public jsonResponse(ResponseInterface $response[, mixed $data = null ][, int $status = 200 ]) : ResponseInterface
Parameters
$response : ResponseInterface
$data : mixed = null
$status : int = 200
Return values
ResponseInterface

        
On this page

Search results