CakeRequest::addDetector PHP Method

addDetector() public method

There are several different formats and types of detectors that can be set. ### Environment value comparison An environment value comparison, compares a value fetched from env() to a known value the environment value is equality checked against the provided value. e.g addDetector('post', array('env' => 'REQUEST_METHOD', 'value' => 'POST')) ### Pattern value comparison Pattern value comparison allows you to compare a value fetched from env() to a regular expression. e.g addDetector('iphone', array('env' => 'HTTP_USER_AGENT', 'pattern' => '/iPhone/i')); ### Option based comparison Option based comparisons use a list of options to create a regular expression. Subsequent calls to add an already defined options detector will merge the options. e.g addDetector('mobile', array('env' => 'HTTP_USER_AGENT', 'options' => array('Fennec'))); ### Callback detectors Callback detectors allow you to provide a 'callback' type to handle the check. The callback will receive the request object as its only parameter. e.g addDetector('custom', array('callback' => array('SomeClass', 'somemethod'))); ### Request parameter detectors Allows for custom detectors on the request parameters. e.g addDetector('requested', array('param' => 'requested', 'value' => 1) You can also make parameter detectors that accept multiple values using the options key. This is useful when you want to check if a request parameter is in a list of options. addDetector('extension', array('param' => 'ext', 'options' => array('pdf', 'csv'))
public addDetector ( string $name, array $options ) : void
$name string The name of the detector.
$options array The options for the detector definition. See above.
return void
    public function addDetector($name, $options)
    {
        $name = strtolower($name);
        if (isset($this->_detectors[$name]) && isset($options['options'])) {
            $options = Hash::merge($this->_detectors[$name], $options);
        }
        $this->_detectors[$name] = $options;
    }

Usage Example

Esempio n. 1
0
 /**
  * Helper method to create an test API request (with the appropriate detector)
  */
 protected function _apiRequest($params)
 {
     $request = new CakeRequest();
     $request->addParams($params);
     $request->addDetector('api', array('callback' => array('CroogoRouter', 'isApiRequest')));
     return $request;
 }
All Usage Examples Of CakeRequest::addDetector