PHP Class lithium\net\http\Response

Inheritance: extends Message
Show file Open project: unionofrad/lithium Class Usage Examples

Public Properties

Property Type Description
$cookies array Cookies are stored as arrays of $name => $value where $value is an associative array or an array of associative arrays which contain at minimum a value key and optionally, expire, path, domain, secure, and/or httponly keys corresponding to the parameters of PHP setcookie().
$encoding string Character encoding.
$status array Status code and message.

Protected Properties

Property Type Description
$_statuses array Status codes.

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor. Adds config values to the public properties when a new object is created.
__toString ( ) : string Return the response as a string.
body ( mixed $data = null, array $options = [] ) : array Add data to or compile and return the HTTP message body, optionally decoding its parts according to content type.
cookies ( string $key = null, string $value = null ) : mixed Add a cookie to header output, or return a single cookie or full cookie list.
digest ( ) : array Looks at the WWW-Authenticate. Will return array of key/values if digest.
status ( string $key = null, string $status = null ) : string Set and get the status for the response.

Protected Methods

Method Description
_cookies ( ) : array Render Set-Cookie headers, urlencoding invalid characters.
_httpChunkedDecode ( string $body ) : string Decodes content bodies transferred with HTTP chunked encoding.
_parseCookies ( array $headers ) Parse Set-Cookie headers.
_parseMessage ( string $body ) : After Accepts an entire HTTP message including headers and body, and parses it into a message body an array of headers, and the HTTP status.

Method Details

__construct() public method

Constructor. Adds config values to the public properties when a new object is created.
See also: lithium\net\http\Message::__construct()
See also: lithium\net\Message::__construct()
public __construct ( array $config = [] ) : void
$config array The available configuration options are the following. Further options are inherited from the parent classes. - `'message'` _string_: Defaults to `null`. - `'status'` _mixed_: Defaults to `null`. - `'type'` _string_: Defaults to `null`. - `'cookies'` _array_: Defaults to `array()`.
return void

__toString() public method

Return the response as a string.
public __toString ( ) : string
return string

_cookies() protected method

NOTE: Technically '+' is a valid character, but many browsers erroneously convert these to spaces, so we must escape this too.
protected _cookies ( ) : array
return array Array of `Set-Cookie` headers or `null` if no cookies to set.

_httpChunkedDecode() protected method

Decodes content bodies transferred with HTTP chunked encoding.
protected _httpChunkedDecode ( string $body ) : string
$body string A chunked HTTP message body.
return string Returns the value of `$body` with chunks decoded, but only if the value of the `Transfer-Encoding` header is set to `'chunked'`. Otherwise, returns `$body` unmodified.

_parseCookies() protected method

Parse Set-Cookie headers.
protected _parseCookies ( array $headers )
$headers array Array of `Set-Cookie` headers or `null` if no cookies to set.

_parseMessage() protected method

Accepts an entire HTTP message including headers and body, and parses it into a message body an array of headers, and the HTTP status.
protected _parseMessage ( string $body ) : After
$body string The full body of the message.
return After parsing out other message components, returns just the message body.

body() public method

Add data to or compile and return the HTTP message body, optionally decoding its parts according to content type.
See also: lithium\net\Message::body()
See also: lithium\net\http\Message::_decode()
public body ( mixed $data = null, array $options = [] ) : array
$data mixed
$options array - `'buffer'` _integer_: split the body string - `'encode'` _boolean_: encode the body based on the content type - `'decode'` _boolean_: decode the body based on the content type
return array

cookies() public method

This function's parameters are designed to be analogous to setcookie(). Function parameters expire, path, domain, secure, and httponly may be passed in as an associative array alongside value inside $value. NOTE: Cookies values are expected to be scalar. This function will not serialize cookie values. If you wish to store a non-scalar value, you must serialize the data first. NOTE: Cookie values are stored as an associative array containing at minimum a value key. Cookies which have been set multiple times do not overwrite each other. Rather they are stored as an array of associative arrays.
public cookies ( string $key = null, string $value = null ) : mixed
$key string
$value string
return mixed

digest() public method

Looks at the WWW-Authenticate. Will return array of key/values if digest.
public digest ( ) : array
return array

status() public method

Set and get the status for the response.
public status ( string $key = null, string $status = null ) : string
$key string Optional. Set to `'code'` or `'message'` to return just the code or message of the status, otherwise returns the full status header.
$status string The code or message of the status you wish to set.
return string Returns the full HTTP status, with version, code and message or dending on $key just the code or message.

Property Details

$_statuses protected property

Status codes.
protected array $_statuses
return array

$cookies public property

Cookies are stored as arrays of $name => $value where $value is an associative array or an array of associative arrays which contain at minimum a value key and optionally, expire, path, domain, secure, and/or httponly keys corresponding to the parameters of PHP setcookie().
See also: lithium\net\http\Response::cookies()
public array $cookies
return array

$encoding public property

Character encoding.
public string $encoding
return string

$status public property

Status code and message.
public array $status
return array