public static match ( |
||
$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;
}