MediaWiki  1.30.0
Wikimedia\Http\HttpAcceptNegotiator Class Reference
Collaboration diagram for Wikimedia\Http\HttpAcceptNegotiator:

Public Member Functions

 __construct (array $supported)
 
 getBestSupportedKey (array $weights, $default=null)
 Returns the best supported key from the given weight map. More...
 
 getFirstSupportedValue (array $preferences, $default=null)
 Returns the first supported value from the given preference list. More...
 

Private Member Functions

 valueMatches ( $accepted, $supported)
 Returns true if the given acceptable value matches the given supported value, according to the HTTP specification. More...
 

Private Attributes

string $defaultValue
 
string[] $supportedValues
 

Detailed Description

Definition at line 18 of file HttpAcceptNegotiator.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Http\HttpAcceptNegotiator::__construct ( array  $supported)
Parameters
string[]$supportedA list of supported values.

Definition at line 33 of file HttpAcceptNegotiator.php.

Member Function Documentation

◆ getBestSupportedKey()

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.

Parameters
float[]$weightsAn associative array mapping accepted values to their respective weights.
null | string$defaultThe value to return if non of the keys in $weights is supported (null per default).
Returns
null|string The best supported key from the $weights parameter.

Definition at line 54 of file HttpAcceptNegotiator.php.

References $name, $value, as, and Wikimedia\Http\HttpAcceptNegotiator\getFirstSupportedValue().

◆ 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.

Parameters
string[]$preferencesA list of acceptable values, in order of preference.
null | string$defaultThe value to return if non of the keys in $weights is supported (null per default).
Returns
null|string The best supported key from the $weights parameter.

Definition at line 90 of file HttpAcceptNegotiator.php.

References $value, as, and Wikimedia\Http\HttpAcceptNegotiator\valueMatches().

Referenced by Wikimedia\Http\HttpAcceptNegotiator\getBestSupportedKey().

◆ valueMatches()

Wikimedia\Http\HttpAcceptNegotiator::valueMatches (   $accepted,
  $supported 
)
private

Returns true if the given acceptable value matches the given supported value, according to the HTTP specification.

The following rules are used:

  • comparison is case-insensitive
  • if $accepted and $supported are equal, they match
  • if $accepted is * or * followed by /*, it matches any $supported value.
  • if both $accepted and $supported contain a /, and $accepted ends with /*, they match if the part before the first / is equal.
Parameters
string$acceptedAn accepted value (may contain wildcards)
string$supportedA supported value.
Returns
bool Whether the given supported value matches the given accepted value.

Definition at line 117 of file HttpAcceptNegotiator.php.

Referenced by Wikimedia\Http\HttpAcceptNegotiator\getFirstSupportedValue().

Member Data Documentation

◆ $defaultValue

string Wikimedia\Http\HttpAcceptNegotiator::$defaultValue
private

Definition at line 28 of file HttpAcceptNegotiator.php.

◆ $supportedValues

string [] Wikimedia\Http\HttpAcceptNegotiator::$supportedValues
private

Definition at line 23 of file HttpAcceptNegotiator.php.


The documentation for this class was generated from the following file: