src/Http/Cgi/Request.php
public function is($flag)
    {
        if (!isset($this->_detectors[$flag])) {
            return $flag === $this->format();
        }
        $detector = $this->_detectors[$flag];

        if (is_callable($detector)) {
            return $detector($this);
        }
        if (!is_array($detector)) {
            throw new Exception("Invalid `'{$flag}'` detector definition.");
        }
        $key = key($detector);
        $check = current($detector);
        $value = $this->attr($key);

        if (is_array($check)) {
            return !!preg_match('~' . join('|', $check) . '~i', $value);
        }
        if (preg_match('~^(?P<char>\~|/|@|#).*?(?P=char)$~', $check)) {
            return !!preg_match($check, $value);
        }
        return $check === $value;
    }
public function is($flag)
    {
        if (!isset($this->_detectors[$flag])) {
            return $flag === $this->format();
        }
        $detector = $this->_detectors[$flag];

        if (is_callable($detector)) {
            return $detector($this);
        }
        if (!is_array($detector)) {
            throw new Exception("Invalid `'{$flag}'` detector definition.");
        }
        $key = key($detector);
        $check = current($detector);
        $value = $this->attr($key);

        if (is_array($check)) {
            return !!preg_match('~' . join('|', $check) . '~i', $value);
        }
        if (preg_match('~^(?P<char>\~|/|@|#).*?(?P=char)$~', $check)) {
            return !!preg_match($check, $value);
        }
        return $check === $value;
    }
public function is ( $ flag ) { if ( ! isset ( $ this -> _detectors [ $ flag ] ) ) { return $ flag === $ this -> format ( ) ; } $ detector = $ this -> _detectors [ $ flag ] ; if ( is_callable ( $ detector ) ) { return $ detector ( $ this ) ; } if ( ! is_array ( $ detector ) ) { throw new Exception ( "Invalid `'{$flag}'` detector definition." ) ; } $ key = key ( $ detector ) ; $ check = current ( $ detector ) ; $ value = $ this -> attr ( $ key ) ; if ( is_array ( $ check ) ) { return ! ! preg_match ( '~' . join ( '|' , $ check ) . '~i' , $ value ) ; } if ( preg_match ( '~^(?P<char>\~|/|@|#).*?(?P=char)$~' , $ check ) ) { return ! ! preg_match ( $ check , $ value ) ; } return $ check === $ value ; }
Provides a simple syntax for making assertions about the properties of a request.

The default detectors include the following:

- `'mobile'`: Uses a regular expression to match common mobile browser user agents.
- `'ajax'`: Checks to see if the `X-Requested-With` header is present, and matches the value
`'XMLHttpRequest'`.
- `'flash'`: Checks to see if the user agent is `'Shockwave Flash'`.
- `'ssl'`: Verifies that the request is SSL-secured.
- `'get'` / `'post'` / `'put'` / `'delete'` / `'head'` / `'options'`: Checks that the HTTP
request method matches the one specified.

In addition to the above, this method also accepts media format names to
make assertions against the format of the request body (for POST or PUT requests), i.e.
`$request->is('json')`. This will return `true` if the client has made a POST request with
JSON data.

For information about adding custom detectors or overriding the ones in the core, see the
`detect()` method.

@param  string  $flag The name of the flag to check, which should be the name of a valid
detector of media format.
@return boolean       Returns `true` if the detector check succeeds of the request match
the media format, otherwise `false`.
Provides a simple syntax for making assertions about the properties of a request .