\Anax\ResponseResponse

Handling a response.

Summary

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

Properties

$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

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.

Parameters

string $url

to redirect to