PHP Class lithium\net\http\Message

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

Public Properties

Property Type Description
$headers array HTTP headers
$protocol string The full protocol: HTTP/1.1
$version string Specification version number

Protected Properties

Property Type Description
$_classes array Classes used by Message and its subclasses.
$_type string Content-Type

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor. Adds config values to the public properties when a new object is created.
body ( mixed $data = null, array $options = [] ) : array Add data to and compile the HTTP message body, optionally encoding or decoding its parts according to content type.
headers ( string | array $key = null, mixed $value = null, boolean $replace = true ) : mixed Adds, gets or removes one or multiple headers at the same time.
type ( string $type = null ) : string Sets/gets the content type.

Protected Methods

Method Description
_decode ( string $body ) : mixed Decode the body based on the content type
_encode ( mixed $body ) : string Encode the body based on the content type

Method Details

__construct() public method

Constructor. Adds config values to the public properties when a new object is created.
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 class. - `'protocol'` _string_: Defaults to `null`. - `'version'` _string_: Defaults to `'1.1'`. - `'scheme'` _string_: Overridden and defaulting to `'http'`. - `'headers'` _array_: Defaults to `array()`.
return void

_decode() protected method

Decode the body based on the content type
See also: lithium\net\http\Message::type()
protected _decode ( string $body ) : mixed
$body string
return mixed

_encode() protected method

Encode the body based on the content type
See also: lithium\net\http\Message::type()
protected _encode ( mixed $body ) : string
$body mixed
return string

body() public method

Add data to and compile the HTTP message body, optionally encoding or decoding its parts according to content type.
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

headers() public method

Header names are not normalized and their casing left untouched. When headers are retrieved no sorting takes place. This behavior is inline with the specification which states header names should be treated in a case-insensitive way. Sorting is suggested but not required. Get single or multiple headers. $request->headers('Content-Type'); // returns 'text/plain' $request->headers(); // returns array('Content-Type: text/plain', ... ) Set single or multiple headers. $request->headers('Content-Type', 'text/plain'); $request->headers(array('Content-Type' => 'text/plain', ...)); Alternatively use full header line. $request->headers('Content-Type: text/plain'); $request->headers(array('Content-Type: text/plain', ...)); Removing single or multiple headers. $request->headers('Content-Type', false); $request->headers(array('Content-Type' => false, ...)); Certain header fields support multiple values. These can be separated by comma or alternatively the header repeated for each value in the list. When explicitly adding a value to an already existing header (that is when $replace is false) an array with those values is kept/created internally. Later when retrieving headers the header will be repeated for each value. Note: Multiple headers of the same name are only valid if the values of that header can be separated by comma as defined in section 4.2 of RFC2616. Replace single or multiple headers $request->headers('Cache-Control', 'no-store'); $request->headers(array('Cache-Control' => 'public')); $request->headers('Cache-Control'); // returns 'public' Merging with existing array headers. Note that new elements are just appended and no sorting takes place. $request->headers('Cache-Control', 'no-store'); $request->headers('Cache-Control', 'no-cache', false); $request->headers(); returns array('Cache-Control: no-store', 'Cache-Control: no-cache') $request->headers('Cache-Control', 'no-store'); $request->headers('Cache-Control', array('no-cache'), false); $request->headers(); returns array('Cache-Control: no-store', 'Cache-Control: no-cache') $request->headers('Cache-Control', 'max-age=0'); $request->headers('Cache-Control', 'no-store, no-cache'); $request->headers(); returns array('Cache-Control: no-store, no-cache')
public headers ( string | array $key = null, mixed $value = null, boolean $replace = true ) : mixed
$key string | array A header name, a full header line (`': '`), or an array of headers to set in `key => value` form.
$value mixed A value to set if `$key` is a string. It can be an array to set multiple headers with the same key. If `null`, returns the value of the header corresponding to `$key`. If `false`, it unsets the header corresponding to `$key`.
$replace boolean Whether to override or add alongside any existing header with the same name.
return mixed When called with just $key provided, the value of a single header or an array of values in case there is multiple headers with this key. When calling the method without any arguments, an array of compiled headers in the form `array(': ', ...)` is returned. All set and replace operations return no value for performance reasons.

type() public method

Sets/gets the content type.
public type ( string $type = null ) : string
$type string A full content type i.e. `'application/json'` or simple name `'json'`
return string A simple content type name, i.e. `'html'`, `'xml'`, `'json'`, etc., depending on the content type of the request.

Property Details

$_classes protected property

Classes used by Message and its subclasses.
protected array $_classes
return array

$_type protected property

Content-Type
protected string $_type
return string

$headers public property

HTTP headers
public array $headers
return array

$protocol public property

The full protocol: HTTP/1.1
public string $protocol
return string

$version public property

Specification version number
public string $version
return string