Pionia Core

BaseResponse
in package

This provides a uniform response format for our entire application.

All requests that hit the application will be handled successfully, so a http status code of 200 OK is expected for all requests whether they resolved with an error or not.

This gives us an opportunity to define our own status code based on the business requirements.

This also helps the server recover gracefully after every panic since all exceptions will be caught and handled

Tags
author

Jet - ezrajet9@gmail.com

Table of Contents

Properties

$data  : Arrayable|null
$extraData  : mixed
$returnCode  : mixed
$returnData  : mixed
$returnMessage  : mixed
$extraData  : mixed
$prettyResponse  : string|null
$response  : array<string|int, mixed>|null
$returnCode  : int
$returnData  : mixed
$returnMessage  : string|null

Methods

__construct()  : mixed
build()  : BaseResponse
This is used to build the response.
getPrettyResponse()  : string|null
jsonResponse()  : BaseResponse
All actions in Pionia must return this as the response. This is how Pionia ensures a uniform response format

Properties

$extraData

public mixed $extraData
  • any other data you want to send to the front-end, any!!

$returnCode

public mixed $returnCode

defaults to 0 for success. Any other code other than 0 implies an error. This can customized to your needs

$returnData

public mixed $returnData
  • the data the server wants to send to the frontend, can be of any data format

$returnMessage

public mixed $returnMessage
  • the message the server wants to send to the frontend

$prettyResponse

private string|null $prettyResponse = null

$response

private array<string|int, mixed>|null $response = null

$returnMessage

private string|null $returnMessage = null

Methods

__construct()

public __construct([mixed $data = null ]) : mixed
Parameters
$data : mixed = null

build()

This is used to build the response.

public build([array<string|int, mixed>|null $additionalData = [] ]) : BaseResponse
Parameters
$additionalData : array<string|int, mixed>|null = []
Return values
BaseResponse

getPrettyResponse()

public getPrettyResponse() : string|null
Return values
string|null

jsonResponse()

All actions in Pionia must return this as the response. This is how Pionia ensures a uniform response format

public static jsonResponse([int|null $code = 0 ][, string|null $message = null ][, mixed|null $data = null ][, array<string|int, mixed>|string|null $extraData = null ]) : BaseResponse
Parameters
$code : int|null = 0
  • the return code to the client side. Defaults to 0 for success
$message : string|null = null
  • the message to send to the client side
$data : mixed|null = null
  • the data to send to the client side
$extraData : array<string|int, mixed>|string|null = null
  • any other data to send to the client side
Return values
BaseResponse

        
On this page

Search results