Restructuring the CakeRequest::is() code and related code a little.

This commit is contained in:
Florian Krämer 2014-11-21 18:49:36 +01:00
parent 24c4cab4f3
commit 17e5d41e55

View file

@ -500,20 +500,14 @@ class CakeRequest implements ArrayAccess {
return false; return false;
} }
$detect = $this->_detectors[$type]; $detect = $this->_detectors[$type];
if (isset($detect['env'])) { if (isset($detect['env']) && $this->_environmentDetector($detect)) {
if ($this->_environmentDetector($detect)) { return true;
return true;
}
} }
if (isset($detect['header'])) { if (isset($detect['header']) && $this->_environmentDetector($detect)) {
if ($this->_environmentDetector($detect)) { return true;
return true;
}
} }
if (isset($detect['param'])) { if (isset($detect['param']) && $this->_paramDetector($detect)) {
if ($this->_paramDetector($detect)) { return true;
return true;
}
} }
if (isset($detect['callback']) && is_callable($detect['callback'])) { if (isset($detect['callback']) && is_callable($detect['callback'])) {
return call_user_func($detect['callback'], $this); return call_user_func($detect['callback'], $this);
@ -528,13 +522,11 @@ class CakeRequest implements ArrayAccess {
*/ */
public function getAcceptHeaders() { public function getAcceptHeaders() {
$headers = array(); $headers = array();
if (function_exists('getallheaders')) { if (isset($_SERVER['HTTP_ACCEPT'])) {
$headers = explode(',', $_SERVER['HTTP_ACCEPT']);
} elseif (function_exists('getallheaders')) {
$headers = getallheaders(); $headers = getallheaders();
$headers = explode(',', $headers['Accept']); $headers = explode(',', $headers['Accept']);
} else {
if (isset($_SERVER['HTTP_ACCEPT'])) {
$headers = explode(',', $_SERVER['HTTP_ACCEPT']);
}
} }
return $headers; return $headers;
} }