Methods
Constructor
__construct(string $body, int $status_code, array $headers) 
Create a new Response object with a dependency injected Headers instance
 
Parameters
$body
stringThe response body's content
 
$status_code
intThe status code
 
$headers
arrayThe response header "hash"
 
  
 
Append a string to the response's content body
append(string $content) : \Klein\Response
Parameters
$content
stringThe 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
stringThe body content string
 
Returns
  
 
Enable response chunking
chunk(string $str) : void
Parameters
$str
stringAn 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
intThe 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
stringThe name of the cookie
 
$value
stringThe value to set the cookie with
 
$expiry
intThe time that the cookie should expire
 
$path
stringThe path of which to restrict the cookie
 
$domain
stringThe domain of which to restrict the cookie
 
$secure
booleanFlag of whether the cookie should only be sent over a HTTPS connection
 
$httponly
booleanFlag of whether the cookie should only be accessible over the HTTP protocol
 
Returns
  
 
Dump a variable
dump(mixed $obj) : void
Parameters
$obj
mixedThe variable to dump
 
  
 
Sends a file
file(string $path, string $filename, string $mimetype) : void
Parameters
$path
stringThe path of the file to send
 
$filename
stringThe file's name
 
$mimetype
stringThe 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
mixedThe data to encode as JSON
 
$jsonp_prefix
stringThe name of the JSON-P function prefix
 
  
 
Prepend a string to the response's content body
prepend(string $content) : \Klein\Response
Parameters
$content
stringThe 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
stringThe URL to redirect to
 
$code
intThe 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
booleanWhether 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
booleanWhether 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