Tsugi

Mimeparse
in package

Mimeparser class. This class provides basic functions for handling mime-types. It can handle matching mime-types against a list of media-ranges. See section 14.1 of the HTTP specification [RFC 2616] for a complete explanation.

It's just a port to php from original Python code (http://code.google.com/p/mimeparse/)

Tags
author

Joe Gregario, Andrew "Venom" K.

ported from version 0.1.2

Comments are mostly excerpted from the original.

Table of Contents

Methods

best_match()  : mixed
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
fitness_and_quality_parsed()  : array<string|int, mixed>
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()
parse_media_range()  : array<string|int, mixed>
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.
parse_mime_type()  : array<string|int, mixed>
Carves up a mime-type and returns an Array of the [type, subtype, params] where "params" is a Hash of all the parameters for the media range.
quality()  : unknown
Returns the quality "q" of a mime-type when compared against the media-ranges in ranges. For example:
quality_parsed()  : float
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()

Methods

best_match()

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

public best_match(array<string|int, mixed> $supported, string $header) : mixed

Mimeparser::best_match(array("application/xbel+xml", "text/xml"), "text/;q=0.5,/*; q=0.1") => "text/xml"

Parameters
$supported : array<string|int, mixed>
$header : string
Return values
mixed —

$mime_type or NULL

fitness_and_quality_parsed()

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()

public fitness_and_quality_parsed(string $mime_type, array<string|int, mixed> $parsed_ranges) : array<string|int, mixed>

Returns the fitness and the "q" quality parameter of the best match, or an array [-1, 0] if no match was found. Just as for Mimeparser::quality(), "parsed_ranges" must be an Enumerable of parsed media ranges.

Parameters
$mime_type : string
$parsed_ranges : array<string|int, mixed>
Return values
array<string|int, mixed> —

($best_fitness, $best_fit_q)

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.

public parse_media_range(string $range) : array<string|int, mixed>

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
$range : string
Return values
array<string|int, mixed> —

($type, $subtype, $params)

parse_mime_type()

Carves up a mime-type and returns an Array of the [type, subtype, params] where "params" is a Hash of all the parameters for the media range.

public parse_mime_type(string $mime_type) : array<string|int, mixed>

For example, the media range "application/xhtml;q=0.5" would get parsed into:

array("application", "xhtml", array( "q" => "0.5" ))

Parameters
$mime_type : string
Return values
array<string|int, mixed> —

($type, $subtype, $params)

quality()

Returns the quality "q" of a mime-type when compared against the media-ranges in ranges. For example:

public quality(unknown_type $mime_type, unknown_type $ranges) : unknown

Mimeparser::quality("text/html", "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, /;q=0.5") => 0.7

Parameters
$mime_type : unknown_type
$ranges : unknown_type
Return values
unknown

quality_parsed()

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()

public quality_parsed(string $mime_type, array<string|int, mixed> $parsed_ranges) : float

Returns the "q" quality parameter of the best match, 0 if no match was found. This function behaves the same as Mimeparser::quality() except that "parsed_ranges" must be an Enumerable of parsed media ranges.

Parameters
$mime_type : string
$parsed_ranges : array<string|int, mixed>
Return values
float —

$q


        
On this page

Search results