Response
extends Error
in package
uses
BaseTraits
Defines the API response object. Response objects are throwable objects that contain response information such as HTTP status code, HTTP status message, API return code, error messages, and API response data. All API Error classes will originate as Response objects.
Table of Contents
Properties
- $_links : ResourceLinkSet
- $code : int
- $data : Model|ModelSet
- $help_text : string
- $message : mixed
- $response_id : string
- $status : string
Methods
- __construct() : mixed
- Constructs a new Response object.
- get_class_fqn() : string
- Obtains the fully qualified name of the called class.
- get_class_shortname() : string
- Obtains the shortname of the called class.
- get_classes_in_namespace() : array<string|int, mixed>
- Obtains all classes associated with this class's current namespace.
- get_http_status_message() : string
- Fetch HTTP status message associated with a given HTTP status code.
- log_error() : void
- Logs an error to the syslog.
- to_openapi_schema() : array<string|int, mixed>
- Represents the Response object as an OpenAPI schema.
- to_representation() : array<string|int, mixed>
- Converts this Response object to an array representation of its contents.
Properties
$_links
public
ResourceLinkSet
$_links
= new ResourceLinkSet()
$code
public
int
$code
= 500
The HTTP status code that corresponds with the API response.
$data
public
Model|ModelSet
$data
= new ModelSet()
$help_text
public
string
$help_text
= ''
A help text message that can be used to describe the API response in more detail.
$message
public
mixed
$message
$response_id
public
string
$response_id
$status
public
string
$status
The HTTP status message that corresponds with the HTTP status code.
Methods
__construct()
Constructs a new Response object.
public
__construct(mixed $message, string $response_id[, Model|ModelSet $data = new ModelSet() ][, ResourceLinkSet $_links = new ResourceLinkSet() ]) : mixed
Parameters
- $message : mixed
-
The verbose message to include in the Response.
- $response_id : string
-
A unique response ID that can be used to identify this specific response. This should be unique from any other Response object in the codebase!
- $data : Model|ModelSet = new ModelSet()
-
A Model or ModelSet this Response relates to. This is typically only included for successful Responses.
- $_links : ResourceLinkSet = new ResourceLinkSet()
-
A ResourceLinkSet containing applicable ResourceLinks for this response.
get_class_fqn()
Obtains the fully qualified name of the called class.
public
get_class_fqn() : string
Return values
string —The FQN for this object's class.
get_class_shortname()
Obtains the shortname of the called class.
public
get_class_shortname() : string
Return values
string —The shortname for this object's class.
get_classes_in_namespace()
Obtains all classes associated with this class's current namespace.
public
get_classes_in_namespace([bool $shortnames = false ]) : array<string|int, mixed>
Parameters
- $shortnames : bool = false
Return values
array<string|int, mixed> —An array of classes currently in this object's namespace
get_http_status_message()
Fetch HTTP status message associated with a given HTTP status code.
public
final static get_http_status_message(int $http_status) : string
Parameters
- $http_status : int
-
The HTTP status code to fetch the descriptive message for.
Return values
string —The HTTP status message associated with the give HTTP response code OR unknown
if not found.
log_error()
Logs an error to the syslog.
public
static log_error(string $message) : void
Parameters
- $message : string
-
The error message to write to the syslog
to_openapi_schema()
Represents the Response object as an OpenAPI schema.
public
to_openapi_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> —This Response object as an OpenAPI schema.
to_representation()
Converts this Response object to an array representation of its contents.
public
to_representation() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array containing the response details.