Negotiation
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
Create a Negotiation instance
No description
Create a Negotiation instance based in string (eg.: curl_opt(..., CURL_OPT_HEADER, true))
Get all languages by Accept-Language header sorted by q-factor (defined by $sort)
Get all languages by Accept-Charset header and sort by q-factor (defined by $sort)
Get all languages by Accept-Encoding header and sort by q-factor (defined by $sort)
Get all document types by Accept header and sorted by q-factor (defined by $sort)
Get the first language with with the greatest q-factor,
if it does not exist then return the value of $alternative
Get the first charset with with the greatest q-factor,
if it does not exist then return the value of $alternative
Get the first encoding with with the greatest q-factor,
if it does not exist then return the value of $alternative
Get the first "document type" with the greatest q-factor,
if it does not exist then return the value of $alternative
Parse any header with q-factor value
Parse and sort a custom value with q-factor
Details
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