mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Microoptimization for ServerRequest::is() and ServerRequest::isAll() (#14654)
This commit is contained in:
parent
9a7c94bad0
commit
8addcf1fa3
1 changed files with 13 additions and 5 deletions
|
@ -508,14 +508,18 @@ class CakeRequest implements ArrayAccess {
|
||||||
* defined with CakeRequest::addDetector(). Any detector can be called
|
* defined with CakeRequest::addDetector(). Any detector can be called
|
||||||
* as `is($type)` or `is$Type()`.
|
* as `is($type)` or `is$Type()`.
|
||||||
*
|
*
|
||||||
* @param string|array $type The type of request you want to check. If an array
|
* @param string|string[] $type The type of request you want to check. If an array
|
||||||
* this method will return true if the request matches any type.
|
* this method will return true if the request matches any type.
|
||||||
* @return bool Whether or not the request is the type you are checking.
|
* @return bool Whether or not the request is the type you are checking.
|
||||||
*/
|
*/
|
||||||
public function is($type) {
|
public function is($type) {
|
||||||
if (is_array($type)) {
|
if (is_array($type)) {
|
||||||
$result = array_map(array($this, 'is'), $type);
|
foreach ($type as $_type) {
|
||||||
return count(array_filter($result)) > 0;
|
if ($this->is($_type)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
$type = strtolower($type);
|
$type = strtolower($type);
|
||||||
if (!isset($this->_detectors[$type])) {
|
if (!isset($this->_detectors[$type])) {
|
||||||
|
@ -643,8 +647,12 @@ class CakeRequest implements ArrayAccess {
|
||||||
* @see CakeRequest::is()
|
* @see CakeRequest::is()
|
||||||
*/
|
*/
|
||||||
public function isAll(array $types) {
|
public function isAll(array $types) {
|
||||||
$result = array_filter(array_map(array($this, 'is'), $types));
|
foreach ($types as $type) {
|
||||||
return count($result) === count($types);
|
if (!$this->is($type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue