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
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.
- getBestLocaleMatch() : string
- Try to find the best matching locale. It supports strict locale comparison.
- 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
$request
Request
        protected
            IncomingRequest
    $request
    
    
    
    
    
    
Methods
__construct()
Constructor
    public
                    __construct([RequestInterface|null $request = null ]) : mixed
    Parameters
- $request : RequestInterface|null = null
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
stringencoding()
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
stringlanguage()
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 strict locale negotiation is disabled and no match is found, the first, highest-ranking client requested type is returned.
Parameters
- $supported : array<string|int, mixed>
Return values
stringmatchLocales()
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
boolmatchTypes()
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
boolmedia()
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
stringparseHeader()
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>setRequest()
Stores the request instance to grab the headers from.
    public
                    setRequest(RequestInterface $request) : $this
    Parameters
- $request : RequestInterface
Return values
$thisgetBestLocaleMatch()
Try to find the best matching locale. It supports strict locale comparison.
    protected
                    getBestLocaleMatch(array<int, string> $supportedLocales, string|null $header) : string
    If Config\App::$supportedLocales have "en-US" and "en-GB" locales, they can be recognized as two different locales. This method checks first for the strict match, then fallback to the most general locale (in this case "en") ISO 639-1 and finally to the locale variant "en-*" (ISO 639-1 plus "wildcard" for ISO 3166-1 alpha-2).
If nothing from above is matched, then it returns the first option from the $supportedLocales array.
Parameters
- $supportedLocales : array<int, string>
- 
                    App-supported values 
- $header : string|null
- 
                    Compatible 'Accept-Language' header string 
Return values
stringgetBestMatch()
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
boolmatchParameters()
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>