Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add an instance cache for is(something) calls
  • Loading branch information
AD7six committed Nov 2, 2014
1 parent c0eb74d commit d6ac630
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Network/Request.php
Expand Up @@ -132,6 +132,13 @@ class Request implements \ArrayAccess {
'requested' => array('param' => 'requested', 'value' => 1)
);

/**
* Instance cache for results of is(something) calls
*
* @var array
*/
protected $_isResults = [];

/**
* Copy of php://input. Since this stream can only be read once in most SAPI's
* keep a copy of it so users don't need to know about that detail.
Expand Down Expand Up @@ -576,6 +583,35 @@ public function __isset($name) {
* @return bool Whether or not the request is the type you are checking.
*/
public function is($type) {
if (!isset($this->_isResults[$type])) {
$this->_isResults[$type] = $this->_is($type);
}

return $this->_isResults[$type];
}

/**
* Read or set the instance is-cache results
*
* @param array|null $results
* @return array|void
*/
public function isCache($results = null) {
if ($results === null) {
return $this->_isResults;
}

$this->_isResults = (array)$results;
}

/**
* Worker for the public is function
*
* @param string|array $type The type of request you want to check. If an array
* this method will return true if the request matches any type.
* @return bool Whether or not the request is the type you are checking.
*/
protected function _is($type) {
if (is_array($type)) {
$result = array_map(array($this, 'is'), $type);
return count(array_filter($result)) > 0;
Expand Down

0 comments on commit d6ac630

Please sign in to comment.