MediaWiki REL1_39
|
Utility for negotiating a value from a set of supported values using a preference list. More...
Public Member Functions | |
__construct (array $supported) | |
getBestSupportedKey (array $weights, $default=null) | |
Returns the best supported key from the given weight map. | |
getFirstSupportedValue (array $preferences, $default=null) | |
Returns the first supported value from the given preference list. | |
Utility for negotiating a value from a set of supported values using a preference list.
This is intended for use with HTTP headers like Accept, Accept-Language, Accept-Encoding, etc. See RFC 2616 section 14 for details.
To use this with a request header, first parse the header value into an array of weights using HttpAcceptParser, then call getBestSupportedKey.
Definition at line 17 of file HttpAcceptNegotiator.php.
Wikimedia\Http\HttpAcceptNegotiator::__construct | ( | array | $supported | ) |
string[] | $supported | A list of supported values. |
Definition at line 32 of file HttpAcceptNegotiator.php.
Wikimedia\Http\HttpAcceptNegotiator::getBestSupportedKey | ( | array | $weights, |
$default = null ) |
Returns the best supported key from the given weight map.
Of the keys from the $weights parameter that are also in the list of supported values supplied to the constructor, this returns the key that has the highest weight associated with it. If two keys have the same weight, the more specific key is preferred, as required by RFC2616 section 14. Keys that map to 0 or false are ignored. If no matching key is found, $default is returned.
float[] | $weights | An associative array mapping accepted values to their respective weights. |
null | string | $default | The value to return if non of the keys in $weights is supported (null per default). |
Definition at line 53 of file HttpAcceptNegotiator.php.
References Wikimedia\Http\HttpAcceptNegotiator\getFirstSupportedValue().
Wikimedia\Http\HttpAcceptNegotiator::getFirstSupportedValue | ( | array | $preferences, |
$default = null ) |
Returns the first supported value from the given preference list.
Of the values from the $preferences parameter that are also in the list of supported values supplied to the constructor, this returns the value that has the lowest index in the list. If no such value is found, $default is returned.
string[] | $preferences | A list of acceptable values, in order of preference. |
null | string | $default | The value to return if non of the keys in $weights is supported (null per default). |
Definition at line 89 of file HttpAcceptNegotiator.php.
Referenced by Wikimedia\Http\HttpAcceptNegotiator\getBestSupportedKey().