Response

package Klein

 Methods

Constructor

__construct(string $body, int $status_code, array $headers) 

Create a new Response object with a dependency injected Headers instance

access public

Parameters

$body

string

The response body's content

$status_code

int

The status code

$headers

array

The response header "hash"

Append a string to the response's content body

append(string $content) : \Klein\Response
access public

Parameters

$content

string

The string to append

Returns

Get (or set) the response's body content

body(string $body) : string | \Klein\Response

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.

access public

Parameters

$body

string

The body content string

Returns

Enable response chunking

chunk(string $str) : void
link https://github.com/chriso/klein.php/wiki/Response-Chunking
link http://bit.ly/hg3gHb
access public

Parameters

$str

string

An optional string to send as a response "chunk"

Get (or set) the HTTP response code

code(int $code) : int | \Klein\Response

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.

access public

Parameters

$code

int

The HTTP status code to send

Returns

Returns the cookies collection

cookies() : \Klein\DataCollection\ResponseCookieDataCollection

Dump a variable

dump(mixed $obj) : void
access public

Parameters

$obj

mixed

The variable to dump

Sends a file

file(string $path, string $filename, string $mimetype) : void
access public

Parameters

$path

string

The path of the file to send

$filename

string

The file's name

$mimetype

string

The MIME type of the file

Sets a response header

header(string $key, mixed $value) : \Klein\Response
access public

Parameters

$key

string

The name of the HTTP response header

$value

mixed

The value to set the header with

Returns

Returns the headers collection

headers() : \Klein\DataCollection\HeaderDataCollection

Check if the response is locked

isLocked() : boolean
access public

Returns

boolean

Check if the response has been sent

isSent() : boolean
access public

Returns

boolean

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

json(mixed $object, string $jsonp_prefix) : void
access public

Parameters

$object

mixed

The data to encode as JSON

$jsonp_prefix

string

The name of the JSON-P function prefix

Lock the response from further modification

lock() : \Klein\Response
access public

Returns

Tell the browser not to cache the response

noCache() : \Klein\Response
access public

Returns

Prepend a string to the response's content body

prepend(string $content) : \Klein\Response
access public

Parameters

$content

string

The string to prepend

Returns

Get (or set) the HTTP protocol version

protocolVersion(string $protocol_version) : string | \Klein\Response

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.

access public

Parameters

$protocol_version

string

Returns

Redirects the request to another URL

redirect(string $url, int $code) : \Klein\Response
access public

Parameters

$url

string

The URL to redirect to

$code

int

The HTTP status code to use for redirection

Returns

Require that the response is unlocked

requireUnlocked() : \Klein\Response

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

access public

Exceptions

\Klein\Exceptions\LockedResponseException If the response is locked

Returns

Send the response and lock it

send(boolean $override) : \Klein\Response
access public

Parameters

$override

boolean

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

Exceptions

\Klein\Exceptions\ResponseAlreadySentException If the response has already been sent

Returns

Send our body's contents

sendBody() : \Klein\Response
access public

Returns

Send our HTTP response cookies

sendCookies(boolean $override) : \Klein\Response
access public

Parameters

$override

boolean

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

Returns

Send our HTTP headers

sendHeaders(boolean $cookies_also, boolean $override) : \Klein\Response
access public

Parameters

$cookies_also

boolean

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

$override

boolean

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

Returns

Returns the status object

status() : \Klein\HttpStatus
access public

Returns

Unlock the response from further modification

unlock() : \Klein\Response
access public

Returns

Generates an HTTP compatible status header line string

httpStatusLine() : string

Creates the string based off of the response's properties

access protected

Returns

string

 Properties

 

$chunked : boolean
access public
 

$body : string
access protected
   

$default_status_code : int
static
access protected
 

$headers : \Klein\DataCollection\HeaderDataCollection
access protected
 

$locked : boolean
access protected
 

$protocol_version : string
access protected
 

$sent : boolean
access protected
 

$status : \Klein\HttpStatus
access protected