MediaWiki REL1_34
|
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. | |
Private Member Functions | |
valueMatches ( $accepted, $supported) | |
Returns true if the given acceptable value matches the given supported value, according to the HTTP specification. | |
Private Attributes | |
string | $defaultValue |
string[] | $supportedValues |
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.
References Wikimedia\Http\HttpAcceptNegotiator\valueMatches().
Referenced by Wikimedia\Http\HttpAcceptNegotiator\getBestSupportedKey().
|
private |
Returns true if the given acceptable value matches the given supported value, according to the HTTP specification.
The following rules are used:
*
or *
followed by /*
, it matches any $supported value./
, and $accepted ends with /*
, they match if the part before the first /
is equal.string | $accepted | An accepted value (may contain wildcards) |
string | $supported | A supported value. |
Definition at line 116 of file HttpAcceptNegotiator.php.
Referenced by Wikimedia\Http\HttpAcceptNegotiator\getFirstSupportedValue().
|
private |
Definition at line 27 of file HttpAcceptNegotiator.php.
|
private |
Definition at line 22 of file HttpAcceptNegotiator.php.