当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP::getAcceptLanguage方法代码示例

本文整理汇总了PHP中SimpleSAML\Utils\HTTP::getAcceptLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::getAcceptLanguage方法的具体用法?PHP HTTP::getAcceptLanguage怎么用?PHP HTTP::getAcceptLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleSAML\Utils\HTTP的用法示例。


在下文中一共展示了HTTP::getAcceptLanguage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getHTTPLanguage

 /**
  * This method returns the preferred language for the user based on the Accept-Language HTTP header.
  *
  * @return string The preferred language based on the Accept-Language HTTP header, or null if none of the languages
  * in the header is available.
  */
 private function getHTTPLanguage()
 {
     $languageScore = HTTP::getAcceptLanguage();
     // for now we only use the default language map. We may use a configurable language map in the future
     $languageMap = self::$defaultLanguageMap;
     // find the available language with the best score
     $bestLanguage = null;
     $bestScore = -1.0;
     foreach ($languageScore as $language => $score) {
         // apply the language map to the language code
         if (array_key_exists($language, $languageMap)) {
             $language = $languageMap[$language];
         }
         if (!in_array($language, $this->availableLanguages, true)) {
             // skip this language - we don't have it
             continue;
         }
         /* Some user agents use very limited precision of the quality value, but order the elements in descending
          * order. Therefore we rely on the order of the output from getAcceptLanguage() matching the order of the
          * languages in the header when two languages have the same quality.
          */
         if ($score > $bestScore) {
             $bestLanguage = $language;
             $bestScore = $score;
         }
     }
     return $bestLanguage;
 }
开发者ID:mrvanes,项目名称:simplesamlphp,代码行数:34,代码来源:Language.php

示例2: getAcceptLanguage

 /**
  * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::getAcceptLanguage() instead.
  */
 public static function getAcceptLanguage()
 {
     return \SimpleSAML\Utils\HTTP::getAcceptLanguage();
 }
开发者ID:jstormes,项目名称:simplesamlphp,代码行数:7,代码来源:Utilities.php

示例3: getHTTPLanguage

 /**
  * This function gets the prefered language for the user based on the Accept-Language http header.
  *
  * @return The prefered language based on the Accept-Language http header, or NULL if none of the
  *         languages in the header were available.
  */
 private function getHTTPLanguage()
 {
     $languageScore = \SimpleSAML\Utils\HTTP::getAcceptLanguage();
     /* For now we only use the default language map. We may use a configurable language map
      * in the future.
      */
     $languageMap = self::$defaultLanguageMap;
     /* Find the available language with the best score. */
     $bestLanguage = NULL;
     $bestScore = -1.0;
     foreach ($languageScore as $language => $score) {
         /* Apply the language map to the language code. */
         if (array_key_exists($language, $languageMap)) {
             $language = $languageMap[$language];
         }
         if (!in_array($language, $this->availableLanguages, TRUE)) {
             /* Skip this language - we don't have it. */
             continue;
         }
         /* Some user agents use very limited precicion of the quality value, but order the
          * elements in descending order. Therefore we rely on the order of the output from
          * getAcceptLanguage() matching the order of the languages in the header when two
          * languages have the same quality.
          */
         if ($score > $bestScore) {
             $bestLanguage = $language;
             $bestScore = $score;
         }
     }
     return $bestLanguage;
 }
开发者ID:jstormes,项目名称:simplesamlphp,代码行数:37,代码来源:Template.php


注:本文中的SimpleSAML\Utils\HTTP::getAcceptLanguage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。