Changes to Cake/Network/CakeRequest.php as discussed on Github for the detector code changes. Fixed the description of a few doc blocks, removed the use of getallheaders(), removed the failsafe (based on extension) for the xml and json detectors.

This commit is contained in:
Florian Krämer 2014-11-22 12:55:22 +01:00
parent 17e5d41e55
commit 83eb8ce7de

View file

@ -112,8 +112,8 @@ class CakeRequest implements ArrayAccess {
'webOS', 'Windows CE', 'Windows Phone OS', 'Xiino'
)),
'requested' => array('param' => 'requested', 'value' => 1),
'json' => array('header' => array('application/json'), 'param' => 'ext', 'value' => 'json'),
'xml' => array('header' => array('application/xml', 'text/xml'), 'param' => 'ext', 'value' => 'xml'),
'json' => array('header' => array('application/json')),
'xml' => array('header' => array('application/xml', 'text/xml')),
);
/**
@ -524,9 +524,6 @@ class CakeRequest implements ArrayAccess {
$headers = array();
if (isset($_SERVER['HTTP_ACCEPT'])) {
$headers = explode(',', $_SERVER['HTTP_ACCEPT']);
} elseif (function_exists('getallheaders')) {
$headers = getallheaders();
$headers = explode(',', $headers['Accept']);
}
return $headers;
}
@ -538,9 +535,9 @@ class CakeRequest implements ArrayAccess {
* @return bool Whether or not the request is the type you are checking.
*/
protected function _headerDetector($detect) {
$headers = $this->getAcceptHeaders();
$acceptHeaders = $this->getAcceptHeaders();
foreach ($detect['header'] as $header) {
if (in_array($header, $headers)) {
if (in_array($header, $acceptHeaders)) {
return true;
}
}
@ -548,7 +545,7 @@ class CakeRequest implements ArrayAccess {
}
/**
* Detects if a specific header is present
* Detects if a specific request parameter is present.
*
* @param array $detect Detector options array.
* @return bool Whether or not the request is the type you are checking.
@ -566,7 +563,7 @@ class CakeRequest implements ArrayAccess {
}
/**
* Detects if a specific header is present
* Detects if a specific environment variable is present.
*
* @param array $detect Detector options array.
* @return bool Whether or not the request is the type you are checking.