StatusTrait uses trait:short
Table of Contents
Properties
- $jsonOptions : int
- The default json options used in the controller.
Methods
- fail() : ResponseInterface|null
- Formats a specific error status message with a code and an errors array representation of all errors.
- initializeJsonOptions() : static
- Initialize the internal $jsonOptions property.
- jsonResponse() : ResponseInterface
- Return a JSON response
- status() : ResponseInterface|null
- Outputs a response status message.
- success() : mixed
- Outputs a success message with a JSON response. If the $response parameter is null, returns the $data parameter value.
Properties
$jsonOptions
The default json options used in the controller.
protected
int
$jsonOptions
= \oihana\enums\JsonParam::JSON_NONE
Methods
fail()
Formats a specific error status message with a code and an errors array representation of all errors.
public
fail(ResponseInterface|null $response[, int|string|null $code = 400 ][, string|null $details = null ][, array<string|int, mixed> $options = [] ]) : ResponseInterface|null
Ex: A 'not acceptable' http request with a failed validation process
return $this->getError( $response , 406 , 'fields validation failed' , [ 'firstName' => 'firstName is required' , 'lastName' => 'lastName must be a string' ] ] ) ;
``
Parameters
- $response : ResponseInterface|null
-
The Response reference.
- $code : int|string|null = 400
-
The status code of the response.
- $details : string|null = null
-
The optional error message to overrides the default status message.
- $options : array<string|int, mixed> = []
-
The optional array to inject in the json object (with an errors)
Return values
ResponseInterface|nullinitializeJsonOptions()
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
Return values
staticjsonResponse()
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
ResponseInterfacestatus()
Outputs a response status message.
public
status(ResponseInterface|null $response[, mixed $message = Char::EMPTY ][, int|string|null $code = 200 ][, array<string|int, mixed>|null $options = null ]) : ResponseInterface|null
Parameters
- $response : ResponseInterface|null
- $message : mixed = Char::EMPTY
-
The message to send.
- $code : int|string|null = 200
-
The status code.
- $options : array<string|int, mixed>|null = null
-
The options to passed-in in the status definition.
Tags
Return values
ResponseInterface|nullsuccess()
Outputs a success message with a JSON response. If the $response parameter is null, returns the $data parameter value.
public
success(ServerRequestInterface|null $request, ResponseInterface|null $response[, mixed $data = null ][, array<string|int, mixed>|null $init = null ]) : mixed
Ex: return $this->success( $request , $response , $data , [ Output::PARAMS => $request->getParams() ] ) ;
Parameters
- $request : ServerRequestInterface|null
-
The HTTP request reference.
- $response : ResponseInterface|null
-
The HTTP Response reference.
- $data : mixed = null
-
The data object to returns (output a JSON object).
- $init : array<string|int, mixed>|null = null
-
An associative definition to initialize the output object with the optional properties :
-
count (int) - The optional number of elements.
owner (object|array) - The optional owner reference.
options (array) - An associative array of optional properties to add in the output object.
params (array) - The optional params to passed-in the getCurrentPath() method when the url option is null.
status (int) - The optional status of the response.
total (int) - The optional total number of elements.
url (string) - The optional url to display.