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

chunk()

chunk(string  $str = null) : \app\framework\Component\Route\Klein\Response

Enable response chunking

Parameters

string $str

An optional string to send as a response "chunk"

Returns

\app\framework\Component\Route\Klein\Response

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

file()

file(string  $path, string  $filename = null, string  $mimetype = null) : \app\framework\Component\Route\Klein\Response

Sends a file

It should be noted that this method disables caching of the response by default, as dynamically created files responses are usually downloads of some type and rarely make sense to be HTTP cached

Also, this method removes any data/content that is currently in the response body and replaces it with the file's data

Parameters

string $path

The path of the file to send

string $filename

The file's name

string $mimetype

The MIME type of the file

Throws

\RuntimeException

Thrown if the file could not be read

Returns

\app\framework\Component\Route\Klein\Response

json()

json(mixed  $object, string  $jsonp_prefix = null) : \app\framework\Component\Route\Klein\Response

Sends an object as json or jsonp by providing the padding prefix

It should be noted that this method disables caching of the response by default, as json responses are usually dynamic and rarely make sense to be HTTP cached

Also, this method removes any data/content that is currently in the response body and replaces it with the passed json encoded object

Parameters

mixed $object

The data to encode as JSON

string $jsonp_prefix

The name of the JSON-P function prefix

Returns

\app\framework\Component\Route\Klein\Response

httpStatusLine()

httpStatusLine() : string

Generates an HTTP compatible status header line string

Creates the string based off of the response's properties

Returns

string