Properties

$chunked

$chunked : 

Whether the response has been chunked or not

Type

$default_status_code

$default_status_code : 

The default response HTTP status code

Type

$protocol_version

$protocol_version : 

The HTTP version of the response

Type

$body

$body : 

The response body

Type

$status

$status : 

HTTP response status

Type

$headers

$headers : 

HTTP response headers

Type

$cookies

$cookies : 

HTTP response cookies

Type

$locked

$locked : 

Whether or not the response is "locked" from any further modification

Type

$sent

$sent : 

Whether or not the response has been sent

Type

Methods

__construct()

__construct(string  $body = '', integer  $status_code = null, array  $headers = array()) 

Constructor

Create a new AbstractResponse object with a dependency injected Headers instance

Parameters

string $body

The response body's content

integer $status_code

The status code

array $headers

The response header "hash"

protocolVersion()

protocolVersion(string  $protocol_version = null) : string|\app\framework\Component\Route\Klein\AbstractResponse

Get (or set) the HTTP protocol version

Simply calling this method without any arguments returns the current protocol version. Calling with an integer argument, however, attempts to set the protocol version to what was provided by the argument.

Parameters

string $protocol_version

Returns

string|\app\framework\Component\Route\Klein\AbstractResponse

body()

body(string  $body = null) : string|\app\framework\Component\Route\Klein\AbstractResponse

Get (or set) the response's body content

Simply calling this method without any arguments returns the current response body. Calling with an argument, however, sets the response body to what was provided by the argument.

Parameters

string $body

The body content string

Returns

string|\app\framework\Component\Route\Klein\AbstractResponse

code()

code(integer  $code = null) : integer|\app\framework\Component\Route\Klein\AbstractResponse

Get (or set) the HTTP response code

Simply calling this method without any arguments returns the current response code. Calling with an integer argument, however, attempts to set the response code to what was provided by the argument.

Parameters

integer $code

The HTTP status code to send

Returns

integer|\app\framework\Component\Route\Klein\AbstractResponse

isLocked()

isLocked() : boolean

Check if the response is locked

Returns

boolean

requireUnlocked()

requireUnlocked() : \app\framework\Component\Route\Klein\AbstractResponse

Require that the response is unlocked

Throws an exception if the response is locked, preventing any methods from mutating the response when its locked

Throws

\app\framework\Component\Route\Klein\Exceptions\LockedResponseException

If the response is locked

Returns

\app\framework\Component\Route\Klein\AbstractResponse

sendHeaders()

sendHeaders(boolean  $cookies_also = true, boolean  $override = false) : \app\framework\Component\Route\Klein\AbstractResponse

Send our HTTP headers

Parameters

boolean $cookies_also

Whether or not to also send the cookies after sending the normal headers

boolean $override

Whether or not to override the check if headers have already been sent

Returns

\app\framework\Component\Route\Klein\AbstractResponse

sendCookies()

sendCookies(boolean  $override = false) : \app\framework\Component\Route\Klein\AbstractResponse

Send our HTTP response cookies

Parameters

boolean $override

Whether or not to override the check if headers have already been sent

Returns

\app\framework\Component\Route\Klein\AbstractResponse

send()

send(boolean  $override = false) : \app\framework\Component\Route\Klein\AbstractResponse

Send the response and lock it

Parameters

boolean $override

Whether or not to override the check if the response has already been sent

Throws

\app\framework\Component\Route\Klein\Exceptions\ResponseAlreadySentException

If the response has already been sent

Returns

\app\framework\Component\Route\Klein\AbstractResponse

isSent()

isSent() : boolean

Check if the response has been sent

Returns

boolean

header()

header(string  $key, mixed  $value) : \app\framework\Component\Route\Klein\AbstractResponse

Sets a response header

Parameters

string $key

The name of the HTTP response header

mixed $value

The value to set the header with

Returns

\app\framework\Component\Route\Klein\AbstractResponse

cookie()

cookie(string  $key, string  $value = '', integer  $expiry = null, string  $path = '/', string  $domain = null, boolean  $secure = false, boolean  $httponly = false) : \app\framework\Component\Route\Klein\AbstractResponse

Sets a response cookie

Parameters

string $key

The name of the cookie

string $value

The value to set the cookie with

integer $expiry

The time that the cookie should expire

string $path

The path of which to restrict the cookie

string $domain

The domain of which to restrict the cookie

boolean $secure

Flag of whether the cookie should only be sent over a HTTPS connection

boolean $httponly

Flag of whether the cookie should only be accessible over the HTTP protocol

Returns

\app\framework\Component\Route\Klein\AbstractResponse

redirect()

redirect(string  $url, integer  $code = 302) : \app\framework\Component\Route\Klein\AbstractResponse

Redirects the request to another URL

Parameters

string $url

The URL to redirect to

integer $code

The HTTP status code to use for redirection

Returns

\app\framework\Component\Route\Klein\AbstractResponse

httpStatusLine()

httpStatusLine() : string

Generates an HTTP compatible status header line string

Creates the string based off of the response's properties

Returns

string