本文整理汇总了PHP中zibo\core\Zibo::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Zibo::getRequest方法的具体用法?PHP Zibo::getRequest怎么用?PHP Zibo::getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zibo\core\Zibo
的用法示例。
在下文中一共展示了Zibo::getRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLocale
/**
* Determines which locale to use, based on the HTTP Accept-Language header.
* @param zibo\library\i18n\locale\LocaleManager $manager The locale manager
* @return null|zibo\library\i18n\locale\Locale the locale
*/
public function getLocale(LocaleManager $manager)
{
$request = $this->zibo->getRequest();
if (!$request) {
return null;
}
$fallbackLanguages = array();
$acceptedLanguages = $request->getAcceptLanguage();
foreach ($acceptedLanguages as $acceptedLanguage => $null) {
if (strpos($acceptedLanguage, self::SEPARATOR_TERRITORY) === false) {
$locale = strtolower($acceptedLanguage);
} else {
list($language, $territory) = explode(self::SEPARATOR_TERRITORY, $acceptedLanguage);
$language = strtolower($language);
$locale = $language . '_' . strtoupper($territory);
$fallbackLanguages[$language] = true;
}
if ($manager->hasLocale($locale)) {
return $manager->getLocale($locale);
}
}
foreach ($fallbackLanguages as $locale => $null) {
if ($manager->hasLocale($locale)) {
return $manager->getLocale($locale);
}
}
return null;
}