\Anax\ResponseResponseUtility

Handling a response and includes utilitie methods.

Summary

Methods
Properties
Constants
setDI()
setStatusCode()
getStatusCode()
addHeader()
checkIfHeadersAlreadySent()
sendHeaders()
setBody()
getBody()
send()
sendJson()
setJsonBody()
redirect()
redirectSelf()
No public properties found
No constants found
No protected methods found
$di
N/A
No private methods found
$headers
$statusCode
$body
$validStatusCode
N/A

Properties

$di

$di : \Anax\DI\Anax\DI\DIInterface

Type

\Anax\DI\Anax\DI\DIInterface — the DI service container.

$headers

$headers : array

Type

array — set all headers to send.

$statusCode

$statusCode : 

Type

$body

$body : 

Type

$validStatusCode

$validStatusCode : array

Type

array — these status codes are supported.

Methods

setDI()

setDI(\Anax\DI\Anax\DI\DIInterface  $di) : self

Set the service container to use

Parameters

\Anax\DI\Anax\DI\DIInterface $di

a service container

Returns

self

setStatusCode()

setStatusCode(  $value) : self

Set status code to be sent as part of headers.

Parameters

$value

Returns

self

getStatusCode()

getStatusCode() : integer

Get status code to be sent as part of headers.

Returns

integer —

value as status code or null if not set.

addHeader()

addHeader(string  $header) : self

Set headers.

Parameters

string $header

type of header to set

Returns

self

checkIfHeadersAlreadySent()

checkIfHeadersAlreadySent() : void

Check if headers are already sent and throw exception if it has, but ignore when running in cli mode.

Throws

\Anax\Response\Exception

sendHeaders()

sendHeaders() : self

Send headers.

Returns

self

setBody()

setBody(callable|string  $body) : self

Set the body.

Parameters

callable|string $body

either a string or a callable that can generate the body.

Returns

self

getBody()

getBody() : string

Get the body.

Returns

string

send()

send(integer  $statusCode = null) : self

Send response with an optional statuscode.

Parameters

integer $statusCode

optional statuscode to send.

Returns

self

sendJson()

sendJson(mixed  $data, integer  $statusCode = null) : self

Send JSON response with an optional statuscode.

Parameters

mixed $data

to be encoded as json.

integer $statusCode

optional statuscode to send.

Returns

self

setJsonBody()

setJsonBody(mixed  $data) : self

Set body with JSON data.

Parameters

mixed $data

to be encoded as json.

Returns

self

redirect()

redirect(string  $url) : void

Redirect to another page and creating an url from the argument.

Parameters

string $url

to redirect to

redirectSelf()

redirectSelf() : void

Redirect to current page.