ICanBoogie
  • Documentation
  • API Reference
  • Operation 4.0.x
Namespaces
  • ICanBoogie
    • Operation
Classes
  • BeforeControlEvent
  • BeforeProcessEvent
  • BeforeValidateEvent
  • ControlEvent
  • FailureEvent
  • GetFormEvent
  • Hooks
  • OperationRouteDefinition
  • OperationRouteDispatcher
  • ProcessEvent
  • RescueEvent
  • Response
  • ValidateEvent
Interfaces
  • Exception
Traits
  • ControlEventTrait
  • ValidateEventTrait
Exceptions
  • Failure
  • FormHasExpired
  • FormNotFound

Class Response

ICanBoogie\HTTP\Response
┗ ICanBoogie\Operation\Response implements ArrayAccess
Namespace: ICanBoogie\Operation
Located at Operation/Response.php

Methods summary

protected set_message( string $message )

Sets the response message.

Sets the response message.

Parameters

$message

Throws

InvalidArgumentException
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

string
public __construct( $body = null, $status = Status::OK, array $headers = [] )

Initializes the ICanBoogie\Operation\Response::$errors property.

Initializes the ICanBoogie\Operation\Response::$errors property.

Inheritdoc

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::$meta 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

array
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

mixed
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

mixed
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

mixed
protected finalize_message( mixed $message ) : string

Finalizes a message.

Finalizes a message.

Parameters

$message

Returns

string
protected finalize_errors( $errors ) : array

Finalizes errors into a nice array.

Finalizes errors into a nice array.

Parameters

$errors

Returns

array
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()
public offsetSet( $offset, $value )

Sets a meta.

Sets a meta.

Inheritdoc

Implementation of

ArrayAccess::offsetSet()
public offsetUnset( $offset )

Unset a meta.

Unset a meta.

Inheritdoc

Implementation of

ArrayAccess::offsetUnset()

Properties summary

public $rc : mixed

Result of the response.

Result of the response.


		
public $errors : ICanBoogie\ErrorCollection

Errors occurring during the response.

Errors occurring during the response.


		
protected $meta : array

Additional response properties.

Additional response properties.

[]

Magic properties

public $message : string

The response message.

public $errors : ICanBoogie\ErrorCollection
Operation 4.0.x – Check on GitHub – API documentation generated by ApiGen