1 | <?php |
||
29 | class AcceptTypes |
||
30 | { |
||
31 | /** |
||
32 | * @var \SplPriorityQueue |
||
33 | */ |
||
34 | private $types; |
||
35 | |||
36 | /** |
||
37 | * Creates a new AcceptTypes. |
||
38 | * |
||
39 | * @param array $server The server variables. (e.g. `$_SERVER`) |
||
40 | */ |
||
41 | 2 | public function __construct(array $server) |
|
51 | |||
52 | /** |
||
53 | * Returns the most preferred MIME type out of the provided list. |
||
54 | * |
||
55 | * This method will iterate through the stored MIME types in preferred order |
||
56 | * and attempt to match them to those provided. |
||
57 | * |
||
58 | * Say for example the HTTP Accept header was: |
||
59 | * `text/html,application/xhtml+xml,application/xml;q=0.9,text/*;q=0.8`. |
||
60 | * |
||
61 | * ```php |
||
62 | * // will return 'text/html' |
||
63 | * $types->preferred(['text/css', 'text/html', 'application/javascript']); |
||
64 | * // will return 'application/xml' |
||
65 | * $types->preferred(['application/xml', 'text/css', 'application/json']); |
||
66 | * // will return 'text/plain' |
||
67 | * $types->preferred(['text/plain', 'text/css', 'application/json']); |
||
68 | * // will return null |
||
69 | * $types->preferred(['application/json', 'application/octet-stream']); |
||
70 | * // will return null |
||
71 | * $types->preferred([]); |
||
72 | * ``` |
||
73 | * |
||
74 | * @param string[] $types The MIME types to compare |
||
75 | * @return string|null The most preferred MIME type or null |
||
76 | */ |
||
77 | 2 | public function preferred(array $types): ?string |
|
99 | } |
||
100 |