本文整理汇总了PHP中Params::SERVER方法的典型用法代码示例。如果您正苦于以下问题:PHP Params::SERVER方法的具体用法?PHP Params::SERVER怎么用?PHP Params::SERVER使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Params
的用法示例。
在下文中一共展示了Params::SERVER方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: negotiateType
/**
* Negotiates the type of the page based on the intersection of what's
* available, and what the client accepts
*
* Sets the $type property to the determined type
*
* @param avail array of mime types that are available to be sreved
* @return void
*/
protected function negotiateType($avail)
{
if (!is_array($avail)) {
$avail = preg_split('/,\\s*/', $avail);
}
$accept = Params::SERVER('HTTP_ACCEPT', 'text/html');
# Fix IE brokeness
if (stripos(Params::SERVER('HTTP_USER_AGENT', ''), 'msie') !== false) {
# In IE 6, the script sets the Accept header to 'foo/bar', yet IE sends '*/*, foo/bar'
$accept = preg_replace('~^\\*/\\*,\\s*~i', '', $accept);
}
$matches = null;
$types = array();
foreach (preg_split('/,\\s*/', $accept) as $type) {
if (($i = strpos($type, ';')) !== false) {
if (preg_match('/q=([\\d\\.]+)/', substr($type, $i), $matches)) {
$q = (double) $matches[1];
} else {
$q = 1.0;
}
$types[substr($type, 0, $i)] = $q;
} else {
$types[$type] = 1.0;
}
}
arsort($types);
foreach (array_keys($types) as $acceptedType) {
if (in_array($acceptedType, $avail)) {
$this->type = $acceptedType;
break;
} else {
$pat = array();
foreach (explode('/', $acceptedType) as $part) {
if ($part == '*') {
array_push($pat, '.+');
} else {
array_push($pat, $part);
}
}
$pat = '/^' . implode('\\/', $pat) . '$/';
foreach ($avail as $type) {
if (preg_match($pat, $type)) {
$this->type = $type;
break;
}
}
if (isset($this->type)) {
break;
}
}
}
if (!isset($this->type)) {
$avail = implode(', ', $avail);
throw new RuntimeException("unable to negotiate page type, available: {$avail} accepted: {$accept}");
}
}