Example #1
0
 /**
  * Returns the first index containing a matching variant, or -1 if not present.
  *
  * @param MatchedPreferenceInterface[] $matchingList
  * @param PreferenceInterface $pref
  *
  * @return int
  */
 private function getMatchingIndex(array $matchingList, PreferenceInterface $pref)
 {
     $index = -1;
     foreach ($matchingList as $key => $match) {
         if ($match->getVariant() === $pref->getVariant()) {
             $index = $key;
         }
     }
     return $index;
 }
Example #2
0
 /**
  * Returns true if the server preference contains a partial language that matches the language in the client
  * preference.
  *
  * e.g. An server variant of en-* would match en, en-US but not es-ES
  *
  * @param string $fromField
  * @param MatchedPreferenceInterface $matchedPreference
  * @param PreferenceInterface $newClientPref
  *
  * @return bool
  */
 private function partialLangMatches($fromField, MatchedPreferenceInterface $matchedPreference, PreferenceInterface $newClientPref)
 {
     $serverPref = $matchedPreference->getServerPreference();
     $oldClientPref = $matchedPreference->getClientPreference();
     // Note that this only supports the simplest case of (e.g.) en-* matching en-GB and en-US, additional
     // Language tags are explicitly ignored
     list($clientMainLang) = explode('-', $newClientPref->getVariant());
     list($serverMainLang) = explode('-', $serverPref->getVariant());
     return PreferenceInterface::LANGUAGE === $fromField && PreferenceInterface::PARTIAL_WILDCARD === $serverPref->getPrecedence() && $clientMainLang == $serverMainLang && $newClientPref->getPrecedence() > $oldClientPref->getPrecedence();
 }
Example #3
0
 /**
  * Returns an array of indexes for of matches of higher precedence than the existing pairing.
  *
  * @param MatchedPreferenceInterface[] $matchingList
  * @param PreferenceInterface $clientPref
  *
  * @return int[]
  */
 private function getMatchingIndexes(array $matchingList, PreferenceInterface $clientPref)
 {
     $matchingIndexList = array();
     foreach ($matchingList as $key => $matching) {
         $serverPref = $matching->getServerPreference();
         list($clientMimeType) = explode('/', $clientPref->getVariant());
         list($serverMimeType) = explode('/', $serverPref->getVariant());
         if ($clientMimeType == $serverMimeType && $clientPref->getPrecedence() > $matching->getClientPreference()->getPrecedence()) {
             $matchingIndexList[] = $key;
         }
     }
     return $matchingIndexList;
 }
Example #4
0
 /**
  * Returns true if the client contained a wildcard or was absent.
  *
  * @return bool
  */
 private function clientWildcardOrAbsent()
 {
     return !(strlen($this->clientPref->getVariant()) && !strstr($this->clientPref->getVariant(), '*'));
 }