class ApiResponse

Api Respnse support JSON format only.

Properties

protected array $result response result
protected array $errors Errors list
protected bool $prettyFormat pretty format json
protected boolean $raw Raw json response
protected ResponseInterface $response Request response object

Methods

__construct(ResponseInterface|null $response = null)

Constructor

useJsonPrettyformat()

Set json pretty format to true

void
addErrors(array $errors)

Add errors

void
setErrors(array $errors)

Set errors

void
clearErrors()

Clear all errors.

void
setError(string $errorMessage, bool $condition = true)

Set error message

withError(string $errorMessage, bool $condition = true)

Set error message

setResult(mixed $data)

Set response result

mixed
getResult()

Get result

mixed
setResponse(bool $condition, array|string|Closure $data, string|Closure $error)

Set response

message(string $message)

Set result message

void
setResultField(string $name, mixed $value)

Set field to result array

field(string $name, mixed $value)

Set result field

mixed
getField(string $name, mixed $default = null)

Get field

int
getErrorCount()

Return errors count

bool
hasError()

Return true if response have error

ResponseInterface
getResponse(bool $raw = false)

Return request response

string
getResponseJson()

Return json

void
setClientResponse(ResponseInterface|null $response = null)

Set client response

Details

at line 62
__construct(ResponseInterface|null $response = null)

Constructor

Parameters

ResponseInterface|null $response

at line 81
ApiResponse useJsonPrettyformat()

Set json pretty format to true

Return Value

ApiResponse

at line 94
void addErrors(array $errors)

Add errors

Parameters

array $errors

Return Value

void

at line 105
void setErrors(array $errors)

Set errors

Parameters

array $errors

Return Value

void

at line 115
void clearErrors()

Clear all errors.

Return Value

void

at line 127
void setError(string $errorMessage, bool $condition = true)

Set error message

Parameters

string $errorMessage
bool $condition

Return Value

void

at line 141
ApiResponse withError(string $errorMessage, bool $condition = true)

Set error message

Parameters

string $errorMessage
bool $condition

Return Value

ApiResponse

at line 154
ApiResponse setResult(mixed $data)

Set response result

Parameters

mixed $data

Return Value

ApiResponse

at line 166
mixed getResult()

Get result

Return Value

mixed

at line 179
mixed setResponse(bool $condition, array|string|Closure $data, string|Closure $error)

Set response

Parameters

bool $condition
array|string|Closure $data
string|Closure $error

Return Value

mixed

at line 202
ApiResponse message(string $message)

Set result message

Parameters

string $message

Return Value

ApiResponse

at line 214
void setResultField(string $name, mixed $value)

Set field to result array

Parameters

string $name
mixed $value

Return Value

void

at line 226
ApiResponse field(string $name, mixed $value)

Set result field

Parameters

string $name
mixed $value

Return Value

ApiResponse

at line 240
mixed getField(string $name, mixed $default = null)

Get field

Parameters

string $name
mixed $default

Return Value

mixed

at line 250
int getErrorCount()

Return errors count

Return Value

int

at line 260
bool hasError()

Return true if response have error

Return Value

bool

at line 272
ResponseInterface getResponse(bool $raw = false)

Return request response

Parameters

bool $raw

Return Value

ResponseInterface

at line 286
string getResponseJson()

Return json

Return Value

string

at line 305
void setClientResponse(ResponseInterface|null $response = null)

Set client response

Parameters

ResponseInterface|null $response

Return Value

void