Creates a _detector_ used with `Request::is()`. A detector is a boolean check that is created to determine something about a request.
A detector check can be either an exact string match or a regular expression match against a header or environment variable. A detector check can also be a closure that accepts the `Request` object instance as a parameter. For example, to detect whether a request is from an iPhone, you can do the following: {{{ $request->detect('iPhone', array('HTTP_USER_AGENT', '/iPhone/')); $isiPhone = $request->is('iPhone'); // returns true if 'iPhone' appears anywhere in the UA }}}

Parameters

  • string $flag The name of the detector check. Used in subsequent calls to `Request::is()`.
  • mixed $detector Detectors can be specified in four different ways: - The name of an HTTP header or environment variable. If a string, calling the detector will check that the header or environment variable exists and is set to a non-empty value. - A two-element array containing a header/environment variable name, and a value to match against. The second element of the array must be an exact match to the header or variable value. - A two-element array containing a header/environment variable name, and a regular expression that matches against the value, as in the example above. - A closure which accepts an instance of the `Request` object and returns a boolean value.

Returns

void

Source

						public function detect($flag, $detector = null) {
		if (is_array($flag)) {
			$this->_detectors = $flag + $this->_detectors;
		} else {
			$this->_detectors[$flag] = $detector;
		}
	}