Skip to content

Commit

Permalink
Changing the direct access of super globals in Cake/Network/CakeReque…
Browse files Browse the repository at this point in the history
…st.php to use env() and fixed a typo.
  • Loading branch information
Florian Krämer committed Nov 29, 2014
1 parent 43f7fcc commit e7f554c
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions lib/Cake/Network/CakeRequest.php
Expand Up @@ -519,20 +519,7 @@ public function is($type) {
}

/**
* Gets the accept header from the current request.
*
* @return bool Returns an array of accept header values.
*/
public function getAcceptHeaders() {
$headers = array();
if (isset($_SERVER['HTTP_ACCEPT'])) {
$headers = explode(',', $_SERVER['HTTP_ACCEPT']);
}
return $headers;
}

/**
* Detects if an URL extension is present.
* Detects if a URL extension is present.
*
* @param array $detect Detector options array.
* @return bool Whether or not the request is the type you are checking.
Expand All @@ -554,7 +541,7 @@ protected function _extensionDetector($detect) {
* @return bool Whether or not the request is the type you are checking.
*/
protected function _acceptHeaderDetector($detect) {
$acceptHeaders = $this->getAcceptHeaders();
$acceptHeaders = explode(',', (string)env('HTTP_ACCEPT'));
foreach ($detect['accept'] as $header) {
if (in_array($header, $acceptHeaders)) {
return true;
Expand All @@ -571,12 +558,12 @@ protected function _acceptHeaderDetector($detect) {
*/
protected function _headerDetector($detect) {
foreach ($detect['header'] as $header => $value) {
$header = 'HTTP_' . strtoupper($header);
if (isset($_SERVER[$header])) {
if (is_callable($value)) {
return call_user_func($value, $_SERVER[$header]);
$header = env('HTTP_' . strtoupper($header));
if (!is_null($header)) {
if (!is_string($value) && !is_bool($value) && is_callable($value)) {
return call_user_func($value, $header);
}
return ($_SERVER[$header] === $value);
return ($header === $value);
}
}
return false;
Expand Down

0 comments on commit e7f554c

Please sign in to comment.