Methods
Constructor
__construct(string $body, int $status_code, array $headers)
Create a new Response object with a dependency injected Headers instance
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
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.
Parameters
$body
string
The body content string
Returns
Enable response chunking
chunk(string $str) : void
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.
Parameters
$code
int
The HTTP status code to send
Returns
Sets a response cookie
cookie(string $key, string $value, int $expiry, string $path, string $domain, boolean $secure, boolean $httponly) : \Klein\Response
Parameters
$key
string
The name of the cookie
$value
string
The value to set the cookie with
$expiry
int
The time that the cookie should expire
$path
string
The path of which to restrict the cookie
$domain
string
The domain of which to restrict the cookie
$secure
boolean
Flag of whether the cookie should only be sent over a HTTPS connection
$httponly
boolean
Flag of whether the cookie should only be accessible over the HTTP protocol
Returns
Dump a variable
dump(mixed $obj) : void
Parameters
$obj
mixed
The variable to dump
Sends a file
file(string $path, string $filename, string $mimetype) : void
Parameters
$path
string
The path of the file to send
$filename
string
The file's name
$mimetype
string
The MIME type of the file
Check if the response is locked
isLocked() : boolean
Check if the response has been sent
isSent() : boolean
Sends an object as json or jsonp by providing the padding prefix
json(mixed $object, string $jsonp_prefix) : void
Parameters
$object
mixed
The data to encode as JSON
$jsonp_prefix
string
The name of the JSON-P function prefix
Prepend a string to the response's content body
prepend(string $content) : \Klein\Response
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.
Parameters
$protocol_version
string
Returns
Redirects the request to another URL
redirect(string $url, int $code) : \Klein\Response
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
Exceptions
Returns
Send the response and lock it
send(boolean $override) : \Klein\Response
Parameters
$override
boolean
Whether or not to override the check if the response has already been sent
Exceptions
Returns
Send our body's contents
sendBody() : \Klein\Response
Send our HTTP response cookies
sendCookies(boolean $override) : \Klein\Response
Parameters
$override
boolean
Whether or not to override the check if headers have already been sent
Returns
Generates an HTTP compatible status header line string
httpStatusLine() : string
Creates the string based off of the response's properties
Returns
string
Properties
$default_status_code : int
$protocol_version : string