PHP Class Flugg\Responder\Http\ErrorResponseBuilder

Author: Alexander Tømmerås ([email protected])
Inheritance: extends ResponseBuilder
Show file Open project: flugger/laravel-responder Class Usage Examples

Protected Properties

Property Type Description
$data array Optional error data appended with the response.
$errorCode string The error code used to identify the error.
$message string A descriptive error message explaining what went wrong.
$parameters array Any parameters used to build the error message.
$statusCode integer The HTTP status code for the response.
$translator Symfony\Component\Translation\TranslatorInterface Translator service used for translating stuff.

Public Methods

Method Description
__construct ( Illuminate\Contracts\Routing\ResponseFactory | ResponseFactory $responseFactory, Symfony\Component\Translation\TranslatorInterface $translator ) Constructor.
addData ( array $data ) : ErrorResponseBuilder Add additonal data appended to the error object.
setError ( string $errorCode = null, string | array | null $message = null ) : ErrorResponseBuilder Set the error code and optionally an error message.
setStatus ( integer $statusCode ) : ResponseBuilder Set the HTTP status code for the response.
toArray ( ) : array Serialize the data and return as an array.

Protected Methods

Method Description
buildErrorData ( ) : array | null Build the error object of the serialized response data.
resolveMessage ( ) : string | null Resolve an error message from the translator.

Method Details

__construct() public method

Constructor.
public __construct ( Illuminate\Contracts\Routing\ResponseFactory | ResponseFactory $responseFactory, Symfony\Component\Translation\TranslatorInterface $translator )
$responseFactory Illuminate\Contracts\Routing\ResponseFactory | Laravel\Lumen\Http\ResponseFactory
$translator Symfony\Component\Translation\TranslatorInterface

addData() public method

Add additonal data appended to the error object.
public addData ( array $data ) : ErrorResponseBuilder
$data array
return ErrorResponseBuilder

buildErrorData() protected method

Build the error object of the serialized response data.
protected buildErrorData ( ) : array | null
return array | null

resolveMessage() protected method

Resolve an error message from the translator.
protected resolveMessage ( ) : string | null
return string | null

setError() public method

Set the error code and optionally an error message.
public setError ( string $errorCode = null, string | array | null $message = null ) : ErrorResponseBuilder
$errorCode string
$message string | array | null
return ErrorResponseBuilder

setStatus() public method

Set the HTTP status code for the response.
public setStatus ( integer $statusCode ) : ResponseBuilder
$statusCode integer
return ResponseBuilder

toArray() public method

Serialize the data and return as an array.
public toArray ( ) : array
return array

Property Details

$data protected property

Optional error data appended with the response.
protected array $data
return array

$errorCode protected property

The error code used to identify the error.
protected string $errorCode
return string

$message protected property

A descriptive error message explaining what went wrong.
protected string $message
return string

$parameters protected property

Any parameters used to build the error message.
protected array $parameters
return array

$statusCode protected property

The HTTP status code for the response.
protected int $statusCode
return integer

$translator protected property

Translator service used for translating stuff.
protected TranslatorInterface,Symfony\Component\Translation $translator
return Symfony\Component\Translation\TranslatorInterface