Arikaim CMS

ApiResponse
in package

Api Respnse support JSON format only.

Table of Contents

Properties

$errors  : array<string|int, mixed>
Errors list
$prettyFormat  : bool
pretty format json
$raw  : bool
Raw json response
$response  : ResponseInterface
Request response object
$result  : array<string|int, mixed>
response result

Methods

__construct()  : mixed
Constructor
addErrors()  : void
Add errors
clearErrors()  : void
Clear all errors.
createErrorResponse()  : self
Create error response
createFromArray()  : self|null
Create api response
createFromJson()  : self|null
Create from json text
field()  : ApiResponse
Set result field
getErrorCount()  : int
Return errors count
getField()  : mixed
Get field
getResponse()  : ResponseInterface
Return request response
getResponseJson()  : string
Return json
getResult()  : mixed
Get result
hasError()  : bool
Return true if response have error
message()  : ApiResponse
Set result message
setClientResponse()  : void
Set client response
setCode()  : void
Set status
setError()  : void
Set error message
setErrors()  : void
Set errors
setResponse()  : mixed
Set response
setResult()  : ApiResponse
Set response result
setResultField()  : void
Set field to result array
setStatus()  : void
Set status
toArray()  : array<string|int, mixed>
Convert to array
useJsonPrettyformat()  : self
Set json pretty format to true
withError()  : ApiResponse
Set error message

Properties

$errors

Errors list

protected array<string|int, mixed> $errors

$prettyFormat

pretty format json

protected bool $prettyFormat

$response

Request response object

protected ResponseInterface $response

$result

response result

protected array<string|int, mixed> $result

Methods

__construct()

Constructor

public __construct([ResponseInterface|null $response = null ]) : mixed
Parameters
$response : ResponseInterface|null = null

addErrors()

Add errors

public addErrors(array<string|int, mixed> $errors) : void
Parameters
$errors : array<string|int, mixed>

clearErrors()

Clear all errors.

public clearErrors() : void

createErrorResponse()

Create error response

public static createErrorResponse([string $error = '' ][, int $errorCode = 404 ][, ResponseInterface|null $response = null ]) : self
Parameters
$error : string = ''
$errorCode : int = 404
$response : ResponseInterface|null = null
Return values
self

createFromArray()

Create api response

public static createFromArray(array<string|int, mixed> $data[, ResponseInterface|null $response = null ]) : self|null
Parameters
$data : array<string|int, mixed>
$response : ResponseInterface|null = null
Return values
self|null

createFromJson()

Create from json text

public static createFromJson(string $json[, ResponseInterface|null $response = null ]) : self|null
Parameters
$json : string
$response : ResponseInterface|null = null
Return values
self|null

getErrorCount()

Return errors count

public getErrorCount() : int
Return values
int

getField()

Get field

public getField(string $name[, mixed $default = null ]) : mixed
Parameters
$name : string
$default : mixed = null

getResponse()

Return request response

public getResponse([bool $raw = false ]) : ResponseInterface
Parameters
$raw : bool = false
Return values
ResponseInterface

getResponseJson()

Return json

public getResponseJson() : string
Return values
string

hasError()

Return true if response have error

public hasError() : bool
Return values
bool

setClientResponse()

Set client response

public setClientResponse([ResponseInterface|null $response = null ]) : void
Parameters
$response : ResponseInterface|null = null

setCode()

Set status

public setCode(mixed $code) : void
Parameters
$code : mixed

setError()

Set error message

public setError(string $errorMessage[, bool $condition = true ]) : void
Parameters
$errorMessage : string
$condition : bool = true

setErrors()

Set errors

public setErrors(array<string|int, mixed> $errors) : void
Parameters
$errors : array<string|int, mixed>

setResponse()

Set response

public setResponse(bool $condition, array<string|int, mixed>|string|Closure $data, string|Closure $error) : mixed
Parameters
$condition : bool
$data : array<string|int, mixed>|string|Closure
$error : string|Closure

setResultField()

Set field to result array

public setResultField(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

setStatus()

Set status

public setStatus(string $status) : void
Parameters
$status : string

toArray()

Convert to array

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

useJsonPrettyformat()

Set json pretty format to true

public useJsonPrettyformat() : self
Return values
self

withError()

Set error message

public withError(string $errorMessage[, bool $condition = true ]) : ApiResponse
Parameters
$errorMessage : string
$condition : bool = true
Return values
ApiResponse

        
On this page

Search results