class Negotiation (View source)

Constants

LOW

Sort values in the header low to high by q-factors

HIGH

Sort values in the header high to low by q-factors

ALL

Get all values from a accept header (without q-factor)

Methods

void
__construct(array $headers = null)

Create a Negotiation instance

static void
fromString(string $str)

Create a Negotiation instance based in string (eg.: `curl_opt(.

array|null
acceptLanguage(int $level = self::HIGH)

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

array|null
acceptCharset(int $level = self::HIGH)

Get all languages by Accept-Charset header and sort by q-factor (defined by $level)

array|null
acceptEncoding(string $level = self::HIGH)

Get all languages by Accept-Encoding header and sort by q-factor (defined by $level)

array|null
accept(int $level = self::HIGH)

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

mixed
getLanguage(mixed $alternative = null)

Get the first language with with the greatest q-factor, if it does not exist then return the value of $alternative

mixed
getCharset(mixed $alternative = null)

Get the first charset with with the greatest q-factor, if it does not exist then return the value of $alternative

mixed
getEncoding(mixed $alternative = null)

Get the first encoding with with the greatest q-factor, if it does not exist then return the value of $alternative

mixed
getAccept(mixed $alternative = null)

Get the first "document type" with the greatest q-factor, if it does not exist then return the value of $alternative

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

Parse any header like TE header or headers with Accepet- prefix

static array
qFactor(string $value, int $level = self::HIGH)

Parse and sort a custom value with q-factor

Details

void __construct(array $headers = null)

Create a Negotiation instance

Parameters

array $headers This parameter is optional, you can set with headers returned by curl or other way

Return Value

void

static void fromString(string $str)

Create a Negotiation instance based in string (eg.: `curl_opt(.

.., CURL_OPT_HEADER, true)`)

Parameters

string $str

Return Value

void

array|null acceptLanguage(int $level = self::HIGH)

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

Parameters

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

Return Value

array|null

Exceptions

Exception

array|null acceptCharset(int $level = self::HIGH)

Get all languages by Accept-Charset header and sort by q-factor (defined by $level)

Parameters

int $level Sorts charsets using LOW or HIGH constants, or return all in an simple array use ALL constant

Return Value

array|null

Exceptions

Exception

array|null acceptEncoding(string $level = self::HIGH)

Get all languages by Accept-Encoding header and sort by q-factor (defined by $level)

Parameters

string $level 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 accept(int $level = self::HIGH)

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

Parameters

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

Return Value

array|null

Exceptions

Exception

mixed getLanguage(mixed $alternative = null)

Get the first language with with the greatest q-factor, 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 getCharset(mixed $alternative = null)

Get the first charset with with the greatest q-factor, 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 getEncoding(mixed $alternative = null)

Get the first encoding with with the greatest q-factor, 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 getAccept(mixed $alternative = null)

Get the first "document type" with the greatest q-factor, 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

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

Parse any header like TE header or headers with Accepet- prefix

Parameters

string $header
int $level

Return Value

array|null

Exceptions

Exception

static array qFactor(string $value, int $level = self::HIGH)

Parse and sort a custom value with q-factor

Parameters

string $value
int $level

Return Value

array

Exceptions

Exception