PHP Класс lithium\net\http\Message

Наследование: extends lithium\net\Message
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$headers array HTTP headers
$protocol string The full protocol: HTTP/1.1
$version string Specification version number

Защищенные свойства (Protected)

Свойство Тип Описание
$_classes array Classes used by Message and its subclasses.
$_type string Content-Type

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_decode ( string $body ) : mixed Decode the body based on the content type
_encode ( mixed $body ) : string Encode the body based on the content type

Описание методов

__construct() публичный Метод

Constructor. Adds config values to the public properties when a new object is created.
См. также: 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()`.
Результат void

_decode() защищенный Метод

Decode the body based on the content type
См. также: lithium\net\http\Message::type()
protected _decode ( string $body ) : mixed
$body string
Результат mixed

_encode() защищенный Метод

Encode the body based on the content type
См. также: lithium\net\http\Message::type()
protected _encode ( mixed $body ) : string
$body mixed
Результат string

body() публичный Метод

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
Результат array

headers() публичный Метод

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.
Результат 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() публичный Метод

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'`
Результат string A simple content type name, i.e. `'html'`, `'xml'`, `'json'`, etc., depending on the content type of the request.

Описание свойств

$_classes защищенное свойство

Classes used by Message and its subclasses.
protected array $_classes
Результат array

$_type защищенное свойство

Content-Type
protected string $_type
Результат string

$headers публичное свойство

HTTP headers
public array $headers
Результат array

$protocol публичное свойство

The full protocol: HTTP/1.1
public string $protocol
Результат string

$version публичное свойство

Specification version number
public string $version
Результат string