public function Mimeparse::parse_media_range in Services 6.3
Same name and namespace in other branches
- 7.3 servers/rest_server/lib/mimeparse.php \Mimeparse::parse_media_range()
Carves up a media range and returns an Array of the [type, subtype, params] where "params" is a Hash of all the parameters for the media range.
For example, the media range "application/*;q=0.5" would get parsed into:
array("application", "*", ( "q", "0.5" ))
In addition this function also guarantees that there is a value for "q" in the params dictionary, filling it in with a proper default if necessary.
Parameters
string $range:
Return value
array ($type, $subtype, $params)
3 calls to Mimeparse::parse_media_range()
- Mimeparse::best_match in servers/
rest_server/ lib/ mimeparse.php - Takes a list of supported mime-types and finds the best match for all the media-ranges listed in header. The value of header must be a string that conforms to the format of the HTTP Accept: header. The value of supported is an Enumerable of mime-types
- Mimeparse::fitness_and_quality_parsed in servers/
rest_server/ lib/ mimeparse.php - Find the best match for a given mime-type against a list of media_ranges that have already been parsed by Mimeparser::parse_media_range()
- Mimeparse::quality in servers/
rest_server/ lib/ mimeparse.php - Returns the quality "q" of a mime-type when compared against the media-ranges in ranges. For example:
File
- servers/
rest_server/ lib/ mimeparse.php, line 56
Class
Code
public function parse_media_range($range) {
list($type, $subtype, $params) = $this
->parse_mime_type($range);
if (!(isset($params['q']) && $params['q'] && floatval($params['q']) && floatval($params['q']) <= 1 && floatval($params['q']) >= 0)) {
$params['q'] = '1';
}
return array(
$type,
$subtype,
$params,
);
}