lithium\net\http\Media::match()
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.
Parameters
-
\lithium\action\Request
$requestThe request to be checked against a set of conditions (if applicable).
-
array
$configRepresents 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, seeMedia::type().
Returns
booleanReturns true if the information in $request matches the type
configuration in $config, otherwise false.
Source
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;
}