\CodeIgniter\HTTPNegotiate

Class Negotiate

Provides methods to negotiate with the HTTP headers to determine the best type match between what the application supports and what the requesting getServer wants.

Summary

Methods
Properties
Constants
__construct()
setRequest()
media()
charset()
encoding()
language()
parseHeader()
matchTypes()
No public properties found
No constants found
getBestMatch()
match()
matchParameters()
$request
N/A
No private methods found
No private properties found
N/A

Properties

Methods

setRequest()

setRequest(\CodeIgniter\HTTP\RequestInterface  $request) : $this

Stores the request instance to grab the headers from.

Parameters

\CodeIgniter\HTTP\RequestInterface $request

Returns

$this

media()

media(array  $supported, boolean  $strictMatch = false) : string

Determines the best content-type to use based on the $supported types the application says it supports, and the types requested by the client.

If no match is found, the first, highest-ranking client requested type is returned.

Parameters

array $supported
boolean $strictMatch

If TRUE, will return an empty string when no match found. If FALSE, will return the first supported element.

Returns

string

charset()

charset(array  $supported) : string

Determines the best charset to use based on the $supported types the application says it supports, and the types requested by the client.

If no match is found, the first, highest-ranking client requested type is returned.

Parameters

array $supported

Returns

string

encoding()

encoding(array  $supported = array()) : string

Determines the best encoding type to use based on the $supported types the application says it supports, and the types requested by the client.

If no match is found, the first, highest-ranking client requested type is returned.

Parameters

array $supported

Returns

string

language()

language(array  $supported) : string

Determines the best language to use based on the $supported types the application says it supports, and the types requested by the client.

If no match is found, the first, highest-ranking client requested type is returned.

Parameters

array $supported

Returns

string

parseHeader()

parseHeader(string  $header) : array

Parses an Accept* header into it's multiple values.

This is based on code from Aura.Accept library.

Parameters

string $header

Returns

array

matchTypes()

matchTypes(array  $acceptable, array  $supported) : boolean

Compares the types/subtypes of an acceptable Media type and the supported string.

Parameters

array $acceptable
array $supported

Returns

boolean

getBestMatch()

getBestMatch(array  $supported, string  $header = null, boolean  $enforceTypes = false, boolean  $strictMatch = false) : string

Does the grunt work of comparing any of the app-supported values against a given Accept* header string.

Portions of this code base on Aura.Accept library.

Parameters

array $supported

App-supported values

string $header

header string

boolean $enforceTypes

If TRUE, will compare media types and sub-types.

boolean $strictMatch

If TRUE, will return empty string on no match. If FALSE, will return the first supported element.

Returns

string —

Best match

match()

match(array  $acceptable, string  $supported, boolean  $enforceTypes = false) : boolean

Match-maker

Parameters

array $acceptable
string $supported
boolean $enforceTypes

Returns

boolean

matchParameters()

matchParameters(array  $acceptable, array  $supported) : boolean

Checks two Accept values with matching 'values' to see if their 'params' are the same.

Parameters

array $acceptable
array $supported

Returns

boolean