CodeIgniter v4.5 API

Negotiate
in package

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 server wants.

Tags
see
http://tools.ietf.org/html/rfc7231#section-5.3
see
NegotiateTest

Table of Contents

Properties

$request  : IncomingRequest
Request

Methods

__construct()  : mixed
Constructor
charset()  : string
Determines the best charset to use based on the $supported types the application says it supports, and the types requested by the client.
encoding()  : 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.
language()  : string
Determines the best language to use based on the $supported types the application says it supports, and the types requested by the client.
matchLocales()  : bool
Will match locales against their broader pairs, so that fr-FR would match a supported localed of fr
matchTypes()  : bool
Compares the types/subtypes of an acceptable Media type and the supported string.
media()  : 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.
parseHeader()  : array<string|int, mixed>
Parses an Accept* header into it's multiple values.
setRequest()  : $this
Stores the request instance to grab the headers from.
getBestMatch()  : string
Does the grunt work of comparing any of the app-supported values against a given Accept* header string.
match()  : bool
Match-maker
matchParameters()  : bool
Checks two Accept values with matching 'values' to see if their 'params' are the same.

Properties

Methods

charset()

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

public charset(array<string|int, mixed> $supported) : string

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

Parameters
$supported : array<string|int, mixed>
Return values
string

encoding()

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

public encoding([array<string|int, mixed> $supported = [] ]) : string

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

Parameters
$supported : array<string|int, mixed> = []
Return values
string

language()

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

public language(array<string|int, mixed> $supported) : string

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

Parameters
$supported : array<string|int, mixed>
Return values
string

matchLocales()

Will match locales against their broader pairs, so that fr-FR would match a supported localed of fr

public matchLocales(array<string|int, mixed> $acceptable, array<string|int, mixed> $supported) : bool
Parameters
$acceptable : array<string|int, mixed>
$supported : array<string|int, mixed>
Return values
bool

matchTypes()

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

public matchTypes(array<string|int, mixed> $acceptable, array<string|int, mixed> $supported) : bool
Parameters
$acceptable : array<string|int, mixed>
$supported : array<string|int, mixed>
Return values
bool

media()

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

public media(array<string|int, mixed> $supported[, bool $strictMatch = false ]) : string

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

Parameters
$supported : array<string|int, mixed>
$strictMatch : bool = false

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

Return values
string

parseHeader()

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

public parseHeader(string $header) : array<string|int, mixed>

This is based on code from Aura.Accept library.

Parameters
$header : string
Return values
array<string|int, mixed>

getBestMatch()

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

protected getBestMatch(array<string|int, mixed> $supported[, string $header = null ][, bool $enforceTypes = false ][, bool $strictMatch = false ][, bool $matchLocales = false ]) : string

Portions of this code base on Aura.Accept library.

Parameters
$supported : array<string|int, mixed>

App-supported values

$header : string = null

header string

$enforceTypes : bool = false

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

$strictMatch : bool = false

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

$matchLocales : bool = false

If TRUE, will match locale sub-types to a broad type (fr-FR = fr)

Return values
string

Best match

match()

Match-maker

protected match(array<string|int, mixed> $acceptable, string $supported[, bool $enforceTypes = false ][, bool $matchLocales = false ]) : bool
Parameters
$acceptable : array<string|int, mixed>
$supported : string
$enforceTypes : bool = false
$matchLocales : bool = false
Return values
bool

matchParameters()

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

protected matchParameters(array<string|int, mixed> $acceptable, array<string|int, mixed> $supported) : bool
Parameters
$acceptable : array<string|int, mixed>
$supported : array<string|int, mixed>
Return values
bool

        
On this page

Search results