Class Response
- ICanBoogie\HTTP\Response
- ┗ ICanBoogie\Operation\Response implements ArrayAccess
Methods summary
protected
set_message( string $message
)
Sets the response message.
Sets the response message.
Parameters
$message
Throws
if the message is an array or an object that do not implement
__toString()
.
protected
get_message( void )
: string
Returns the response message.
Returns the response message.
Returns
public
__construct( $body
= null, $status
= 200, array $headers
= [] )
Initializes the ICanBoogie\Operation\Response::$errors
property.
protected
finalize( ICanBoogie\HTTP\Headers & $headers
, & $body
)
If $body
is null the function does nothing.
If $body
is null the function does nothing.
If ICanBoogie\Operation\Response::$rc
is a closure $body
is set to ICanBoogie\Operation\Response::$rc
.
Otherwise a JSON string is created with the message, errors and ICanBoogie\Operation\Response::$metas
of the
response. If the response is successful the ICanBoogie\Operation\Response::$rc
property is also present. This JSON
string is set in $body
. The Content-Type
header field is set to
"application/json" and the Content-Length
header field is set to the length of the JSON
string.
Inheritdoc
protected
finalize_as_array( $rc
)
: array
Finalizes the response as an array.
Finalizes the response as an array.
The array contains the following keys:
rc
: The result of the operation. This key absent if the response is not successful.message
: The message associated with the response, a success or error message.errors
: An array of errors, which might only be present if the response is not successful.
Parameters
$rc
Returns
protected
finalize_as_json( array $rc
, ICanBoogie\HTTP\Headers & $headers
, mixed & $body
)
Finalizes the response as a JSON string.
Finalizes the response as a JSON string.
The following methods are invoked
Parameters
$rc
$headers
$body
protected
finalize_value( mixed $value
)
: mixed
Tries to transforms a value into a simple type such as a scalar or an array.
Tries to transforms a value into a simple type such as a scalar or an array.
The following transformations occur:
$value
is an object and implements__toString
: A string is returned.$value
is an object and implements ICanBoogie\ToArrayRecursive: An array is returned.$value
is an object and implements ICanBoogie\ToArray: An array is returned.
Otherwise the value is returned as is.
Parameters
$value
Returns
protected
finalize_value_object( $value
)
: mixed
Finalizes value object.
Finalizes value object.
- If the value implements
__toString
the value is cast as a string. - If the value is an instance of ICanBoogie\ToArrayRecursive the value is converted into an array.
- If the value is an instance of ICanBoogie\ToArray the value is converted into an array.
- Otherwise the value is returned as is.
Parameters
$value
Returns
protected
finalize_rc( mixed $rc
)
: mixed
Finalizes a value of the ICanBoogie\Operation\Response::$rc
property using ICanBoogie\Operation\Response::finalize_value()
.
Finalizes a value of the ICanBoogie\Operation\Response::$rc
property using ICanBoogie\Operation\Response::finalize_value()
.
Parameters
$rc
Returns
protected
finalize_message( mixed $message
)
: string
Finalizes a message.
Finalizes a message.
Parameters
$message
Returns
protected
finalize_errors( $errors
)
: array
Finalizes errors into a nice array.
Finalizes errors into a nice array.
Parameters
$errors
Returns
public
offsetExists( $offset
)
Checks if a meta exists.
Checks if a meta exists.
Inheritdoc
Implementation of
ArrayAccess::offsetExists()
public
offsetGet( $offset
)
Returns a meta or null if it is not defined.
Returns a meta or null if it is not defined.
Inheritdoc
Implementation of
ArrayAccess::offsetGet()