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

__destruct()

No description

static void
fromString(string $str)

Create a Negotiation instance based in string (eg.: curl_opt(..., CURL_OPT_HEADER, true))

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

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

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

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

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

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

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

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

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 $sort = self::HIGH)

Parse any header with q-factor value

static array
qFactor(string $value, int $sort = 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

__destruct()

No description

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 $sort = self::HIGH)

Get all languages by 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

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

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

Parameters

int $sort

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 $sort = self::HIGH)

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

Parameters

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

Get all document types by 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

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 $sort = self::HIGH)

Parse any header with q-factor value

Parameters

string $header
int $sort

Return Value

array|null

Exceptions

Exception

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

Parse and sort a custom value with q-factor

Parameters

string $value
int $sort

Return Value

array

Exceptions

Exception