class Negotiation (View source)

Constants

LOW

HIGH

ALL

Methods

__construct(array $headers = array())

Create a Negotiation instance from request headers or from a Array

static Negotiation
fromString(string $str)

Create a Negotiation instance based in string

array|null
entries(string $header, int $sort = self::HIGH)

Parse any header with q-factor value

array|null
contentTypes(int $sort = self::HIGH)

Get all document types from Accept header and sorted by q-factor (defined by $sort)

array|null
encodings(int $sort = self::HIGH)

Get all encodings from Accept-Encoding header and sort by q-factor (defined by $sort)

array|null
languages(int $sort = self::HIGH)

Get all languages from Accept-Language header sorted by q-factor (defined by $sort)

mixed
top(mixed $header, mixed $alternative)

Get the highest priority option from the header

mixed
topContentType(mixed $alternative = null)

Get the document type (from Accept header) with the highest priority based on the q value. If it does not exist then return the value of $alternative.

mixed
topEncoding(mixed $alternative = null)

Get the encoding (from Accept-Encoding header) with the highest priority based on the q value. If it does not exist then return the value of $alternative.

mixed
topLanguage(mixed $alternative = null)

Get the encoding (from Accept-Language header) with the highest priority based on the q value. If it does not exist then return the value of $alternative.

static array
qFactor(string $value, Negotiation::LOW|Negotiation::HIGH|Negotiation::ALL $sort = self::HIGH)

Parse and sort a custom value with q-factor

Details

__construct(array $headers = array())

Create a Negotiation instance from request headers or from a Array

Parameters

array $headers

Optional. You can set with headers returned by cURL or other way

static Negotiation fromString(string $str)

Create a Negotiation instance based in string

Parameters

string $str

Return Value

Negotiation

array|null entries(string $header, int $sort = self::HIGH)

Parse any header with q-factor value

Parameters

string $header
int $sort

Return Value

array|null

Exceptions

Exception

array|null contentTypes(int $sort = self::HIGH)

Get all document types from Accept header and sorted by q-factor (defined by $sort)

Parameters

int $sort

Sorts types using LOW or HIGH constants, or return all in an simple array use ALL constant

Return Value

array|null

Exceptions

Exception

array|null encodings(int $sort = self::HIGH)

Get all encodings from Accept-Encoding header and sort by q-factor (defined by $sort)

Parameters

int $sort

Sorts encodings using LOW or HIGH constants, or return all in an simple array use ALL constant

Return Value

array|null

Exceptions

Exception

array|null languages(int $sort = self::HIGH)

Get all languages from Accept-Language header sorted by q-factor (defined by $sort)

Parameters

int $sort

Sorts languages using LOW or HIGH constants, or return all in an simple array use ALL constant

Return Value

array|null

Exceptions

Exception

mixed top(mixed $header, mixed $alternative)

Get the highest priority option from the header

Parameters

mixed $header
mixed $alternative

Define alternative value, this value will be used does not have the "header"

Return Value

mixed

Exceptions

Exception

mixed topContentType(mixed $alternative = null)

Get the document type (from Accept header) with the highest priority based on the q value. If it does not exist then return the value of $alternative.

Parameters

mixed $alternative

Define alternative value, this value will be used does not have the "header"

Return Value

mixed

Exceptions

Exception

mixed topEncoding(mixed $alternative = null)

Get the encoding (from Accept-Encoding header) with the highest priority based on the q value. If it does not exist then return the value of $alternative.

Parameters

mixed $alternative

Define alternative value, this value will be used does not have the "header"

Return Value

mixed

Exceptions

Exception

mixed topLanguage(mixed $alternative = null)

Get the encoding (from Accept-Language header) with the highest priority based on the q value. If it does not exist then return the value of $alternative.

Parameters

mixed $alternative

Define alternative value, this value will be used does not have the "header"

Return Value

mixed

Exceptions

Exception

static array qFactor(string $value, Negotiation::LOW|Negotiation::HIGH|Negotiation::ALL $sort = self::HIGH)

Parse and sort a custom value with q-factor

Parameters

string $value
Negotiation::LOW|Negotiation::HIGH|Negotiation::ALL $sort

Return Value

array

Exceptions

Exception