lithium\net\http\Media::match PHP Method

match() public static method

Assists Media::negotiate() in processing the negotiation conditions of a content type, by iterating through the conditions and checking each one against the Request object.
See also: lithium\net\http\Media::negotiate()
See also: lithium\net\http\Media::type()
See also: lithium\action\Request
public static match ( Request $request, array $config ) : boolean
$request lithium\action\Request The request to be checked against a set of conditions (if applicable).
$config array Represents a content type configuration, which is an array containing 3 keys: - `'name'` _string_: The type name, i.e. `'html'` or `'json'`. - `'content'` _mixed_: One or more content types that the configuration represents, i.e. `'text/html'`, `'application/xhtml+xml'` or `'application/json'`, or an array containing multiple content types. - `'options'` _array_: An array containing rendering information, and an optional `'conditions'` key, which contains an array of matching parameters. For more details on these matching parameters, see `Media::type()`.
return boolean Returns `true` if the information in `$request` matches the type configuration in `$config`, otherwise false.
    public static function match($request, array $config)
    {
        if (!isset($config['options']['conditions'])) {
            return true;
        }
        $conditions = $config['options']['conditions'];
        foreach ($conditions as $key => $value) {
            switch (true) {
                case $key === 'type':
                    if ($value !== ($request->type === $config['name'])) {
                        return false;
                    }
                    break;
                case strpos($key, ':'):
                    if ($request->get($key) !== $value) {
                        return false;
                    }
                    break;
                case $request->is($key) !== $value:
                    return false;
                    break;
            }
        }
        return true;
    }