1 | <?php |
||
18 | class Mimeparse |
||
19 | { |
||
20 | /** |
||
21 | * Parses a media-range and returns an array with its components. |
||
22 | * |
||
23 | * The returned array contains: |
||
24 | * |
||
25 | * 1. type: The type categorization. |
||
26 | * 2. subtype: The subtype categorization. |
||
27 | * 3. params: An associative array of all the parameters for the |
||
28 | * media-range. |
||
29 | * 4. generic subtype: A more generic subtype, if one is present. See |
||
30 | * http://tools.ietf.org/html/rfc3023#appendix-A.12 |
||
31 | * |
||
32 | * For example, the media-range "application/xhtml+xml;q=0.5" would get |
||
33 | * parsed into: |
||
34 | * |
||
35 | * array("application", "xhtml+xml", array( "q" => "0.5" ), "xml") |
||
36 | * |
||
37 | * @param string $mediaRange |
||
38 | * @return array ($type, $subtype, $params, $genericSubtype) |
||
39 | * @throws UnexpectedValueException when $mediaRange does not include a |
||
40 | * valid subtype |
||
41 | */ |
||
42 | public static function parseMediaRange($mediaRange) |
||
77 | |||
78 | |||
79 | /** |
||
80 | * Parses a media-range via Mimeparse::parseMediaRange() and guarantees that |
||
81 | * there is a value for the "q" param, filling it in with a proper default |
||
82 | * if necessary. |
||
83 | * |
||
84 | * @param string $mediaRange |
||
85 | * @return array ($type, $subtype, $params, $genericSubtype) |
||
86 | */ |
||
87 | protected static function parseAndNormalizeMediaRange($mediaRange) |
||
102 | |||
103 | /** |
||
104 | * Find the best match for a given mime-type against a list of |
||
105 | * media-ranges that have already been parsed by |
||
106 | * Mimeparse::parseAndNormalizeMediaRange() |
||
107 | * |
||
108 | * Returns the fitness and the "q" quality parameter of the best match, or |
||
109 | * an array [-1, 0] if no match was found. Just as for |
||
110 | * Mimeparse::quality(), $parsedRanges must be an array of parsed |
||
111 | * media-ranges. |
||
112 | * |
||
113 | * @param string $mimeType |
||
114 | * @param array $parsedRanges |
||
115 | * @return array ($bestFitQuality, $bestFitness) |
||
116 | */ |
||
117 | protected static function qualityAndFitnessParsed($mimeType, $parsedRanges) |
||
149 | |||
150 | /** |
||
151 | * Find the best match for a given mime-type against a list of |
||
152 | * media-ranges that have already been parsed by |
||
153 | * Mimeparse::parseAndNormalizeMediaRange() |
||
154 | * |
||
155 | * Returns the "q" quality parameter of the best match, 0 if no match was |
||
156 | * found. This function behaves the same as Mimeparse::quality() except |
||
157 | * that $parsedRanges must be an array of parsed media-ranges. |
||
158 | * |
||
159 | * @param string $mimeType |
||
160 | * @param array $parsedRanges |
||
161 | * @return float $q |
||
162 | */ |
||
163 | protected static function qualityParsed($mimeType, $parsedRanges) |
||
168 | |||
169 | /** |
||
170 | * Returns the quality "q" of a mime-type when compared against the |
||
171 | * media-ranges in ranges. For example: |
||
172 | * |
||
173 | * Mimeparse::quality("text/html", "text/*;q=0.3, text/html;q=0.7, |
||
174 | * text/html;level=1, text/html;level=2;q=0.4, *\/*;q=0.5") |
||
175 | * => 0.7 |
||
176 | * |
||
177 | * @param string $mimeType |
||
178 | * @param string $ranges |
||
179 | * @return float |
||
180 | */ |
||
181 | public static function quality($mimeType, $ranges) |
||
191 | |||
192 | /** |
||
193 | * Takes a list of supported mime-types and finds the best match for all |
||
194 | * the media-ranges listed in header. The value of $header must be a |
||
195 | * string that conforms to the format of the HTTP Accept: header. The |
||
196 | * value of $supported is an array of mime-types. |
||
197 | * |
||
198 | * In case of ties the mime-type with the lowest index in $supported will |
||
199 | * be used. |
||
200 | * |
||
201 | * Mimeparse::bestMatch(array("application/xbel+xml", "text/xml"), "text/*;q=0.5,*\/*; q=0.1") |
||
202 | * => "text/xml" |
||
203 | * |
||
204 | * @param array $supported |
||
205 | * @param string $header |
||
206 | * @return mixed $mimeType or NULL |
||
207 | */ |
||
208 | public static function bestMatch($supported, $header) |
||
238 | |||
239 | /** |
||
240 | * Disable access to constructor |
||
241 | * |
||
242 | * @codeCoverageIgnore |
||
243 | */ |
||
244 | private function __construct() |
||
247 | } |
||
248 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.