trait ApiResponse

ApiResponse trait

Properties

protected array $result Response result
protected bool $prettyFormat pretty format json

Methods

ResponseInterface
getResponse(bool $raw = false)

Return response

ApiController
message(string $name)

Add message to response, first find in messages array if not found display name value as message

Self
field(string $name, mixed $value)

Set result field

Self
useJsonPrettyformat()

Set json pretty format to true

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

Set response

Self
setResult(mixed $data)

Set response result

void
clearResult()

Clear result

void
setResultField(string $name, mixed $value)

Set field to result array

void
setResultFields(array $values, string|null $filedName = null)

Set result filelds

string
getResponseJson(bool $raw = false)

Return json

Details

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

Return response

Parameters

bool $raw

Return Value

ResponseInterface

at line 55
ApiController message(string $name)

Add message to response, first find in messages array if not found display name value as message

Parameters

string $name

Return Value

ApiController

at line 72
Self field(string $name, mixed $value)

Set result field

Parameters

string $name
mixed $value

Return Value

Self

at line 84
Self useJsonPrettyformat()

Set json pretty format to true

Return Value

Self

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

Set response

Parameters

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

Return Value

mixed

at line 124
Self setResult(mixed $data)

Set response result

Parameters

mixed $data

Return Value

Self

at line 136
void clearResult()

Clear result

Return Value

void

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

Set field to result array

Parameters

string $name
mixed $value

Return Value

void

at line 165
void setResultFields(array $values, string|null $filedName = null)

Set result filelds

Parameters

array $values
string|null $filedName

Return Value

void

at line 182
string getResponseJson(bool $raw = false)

Return json

Parameters

bool $raw

Return Value

string