CakeRequest::is PHP Method

is() public method

Uses the built in detection rules as well as additional rules defined with CakeRequest::addDetector(). Any detector can be called as is($type) or is$Type().
public is ( string | array $type ) : boolean
$type string | array The type of request you want to check. If an array this method will return true if the request matches any type.
return boolean Whether or not the request is the type you are checking.
    public function is($type)
    {
        if (is_array($type)) {
            $result = array_map(array($this, 'is'), $type);
            return count(array_filter($result)) > 0;
        }
        $type = strtolower($type);
        if (!isset($this->_detectors[$type])) {
            return false;
        }
        $detect = $this->_detectors[$type];
        if (isset($detect['env']) && $this->_environmentDetector($detect)) {
            return true;
        }
        if (isset($detect['header']) && $this->_headerDetector($detect)) {
            return true;
        }
        if (isset($detect['accept']) && $this->_acceptHeaderDetector($detect)) {
            return true;
        }
        if (isset($detect['param']) && $this->_paramDetector($detect)) {
            return true;
        }
        if (isset($detect['callback']) && is_callable($detect['callback'])) {
            return call_user_func($detect['callback'], $this);
        }
        return false;
    }

Usage Example

Esempio n. 1
0
 public function getUser(CakeRequest $request)
 {
     if ($request->is('post') && isset($request->data['password'])) {
         $password = $request->data['password'];
         if ($this->checkPassword($password)) {
             return array('loggedin' => true);
         } else {
             throw new ForbiddenException(__('Wrong Password'));
         }
     }
     return false;
 }
All Usage Examples Of CakeRequest::is