class Header implements Serializable (View source)

The http\Header class provides methods to manipulate, match, negotiate and serialize HTTP headers.

Constants

MATCH_LOOSE

None of the following match constraints applies.

MATCH_CASE

Perform case sensitive matching.

MATCH_WORD

Match only on word boundaries (according by CType alpha-numeric).

MATCH_FULL

Match the complete string.

MATCH_STRICT

Case sensitively match the full string (same as MATCH_CASE|MATCH_FULL).

Properties

string $name

The name of the HTTP header.

mixed $value

The value of the HTTP header.

Methods

__construct(string $name = null, mixed $value = null)

Create an http\Header instance for use of simple matching or negotiation. If the value of the header is an array it may be compounded to a single comma separated string.

string
__toString()

String cast handler. Alias of http\Header::serialize().

getParams(mixed $ps = null, mixed $as = null, mixed $vs = null, int $flags = null)

Create a parameter list out of the HTTP header value.

bool
match(string $value, int $flags = null)

Match the HTTP header's value against provided $value according to $flags.

string|null
negotiate(array $supported, array $result = null)

Negotiate the header's value against a list of supported values in $supported.

array|false
parse(string $header, string $header_class = null)

Parse HTTP headers.

string|null
serialize()

Implements Serializable.

string
toString()

Convenience method. Alias of http\Header::serialize().

void
unserialize(string $serialized)

Implements Serializable.

Details

__construct(string $name = null, mixed $value = null)

Create an http\Header instance for use of simple matching or negotiation. If the value of the header is an array it may be compounded to a single comma separated string.

Parameters

string $name

The HTTP header name.

mixed $value

The value of the header.

Throws:

string __toString()

String cast handler. Alias of http\Header::serialize().

Return Value

string

the serialized form of the HTTP header (i.e. "Name: value").

Params getParams(mixed $ps = null, mixed $as = null, mixed $vs = null, int $flags = null)

Create a parameter list out of the HTTP header value.

Parameters

mixed $ps

The parameter separator(s).

mixed $as

The argument separator(s).

mixed $vs

The value separator(s).

int $flags

The modus operandi. See http\Params constants.

Return Value

Params instance

bool match(string $value, int $flags = null)

Match the HTTP header's value against provided $value according to $flags.

Parameters

string $value

The comparison value.

int $flags

The modus operandi. See http\Header constants.

Return Value

bool

whether $value matches the header value according to $flags.

string|null negotiate(array $supported, array $result = null)

Negotiate the header's value against a list of supported values in $supported.

Negotiation operation is adopted according to the header name, i.e. if the header being negotiated is Accept, then a slash is used as primary type separator, and if the header is Accept-Language respectively, a hyphen is used instead.

NOTE: The first element of $supported serves as a default if no operand matches.

Parameters

array $supported

The list of supported values to negotiate.

array $result

Out parameter recording the negotiation results.

Return Value

string|null

NULL if negotiation fails. or string the closest match negotiated, or the default (first entry of $supported).

array|false parse(string $header, string $header_class = null)

Parse HTTP headers.

See also http\Header\Parser.

Parameters

string $header

The complete string of headers.

string $header_class

A class extending http\Header.

Return Value

array|false

array of parsed headers, where the elements are instances of $header_class if specified. or false if parsing fails.

string|null serialize()

Implements Serializable.

Return Value

string|null

The string representation of the object or null

string toString()

Convenience method. Alias of http\Header::serialize().

Return Value

string

the serialized form of the HTTP header (i.e. "Name: value").

void unserialize(string $serialized)

Implements Serializable.

Parameters

string $serialized

The serialized HTTP header (i.e. "Name: value")

Return Value

void