1 | <?php namespace Neomerx\JsonApi\Http\Headers; |
||
25 | class MediaType implements MediaTypeInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $type; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $subType; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $mediaType; |
||
41 | |||
42 | /** |
||
43 | * @var array<string,string>|null |
||
44 | */ |
||
45 | private $parameters; |
||
46 | |||
47 | /** |
||
48 | * A list of parameter names for case-insensitive compare. Keys must be lower-cased. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $ciParams = [ |
||
53 | 'charset' => true, |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * @param string $type |
||
58 | * @param string $subType |
||
59 | * @param array<string,string>|null $parameters |
||
60 | */ |
||
61 | 73 | public function __construct($type, $subType, array $parameters = null) |
|
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | 33 | public function getType() |
|
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | 32 | public function getSubType() |
|
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | 33 | public function getMediaType() |
|
102 | |||
103 | /** |
||
104 | * @inheritdoc |
||
105 | */ |
||
106 | 47 | public function getParameters() |
|
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | 26 | public function matchesTo(MediaTypeInterface $mediaType) |
|
121 | |||
122 | /** |
||
123 | * @inheritdoc |
||
124 | */ |
||
125 | 18 | public function equalsTo(MediaTypeInterface $mediaType) |
|
132 | |||
133 | /** |
||
134 | * Parse media type. |
||
135 | * |
||
136 | * @param int $position |
||
137 | * @param string $mediaType |
||
138 | * |
||
139 | * @return MediaType |
||
140 | */ |
||
141 | 40 | public static function parse($position, $mediaType) |
|
166 | |||
167 | /** |
||
168 | * @param MediaTypeInterface $mediaType |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | 26 | private function isTypeMatches(MediaTypeInterface $mediaType) |
|
176 | |||
177 | /** |
||
178 | * @param MediaTypeInterface $mediaType |
||
179 | * |
||
180 | * @return bool |
||
181 | */ |
||
182 | 26 | private function isTypeEquals(MediaTypeInterface $mediaType) |
|
188 | |||
189 | /** |
||
190 | * @param MediaTypeInterface $mediaType |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | 25 | private function isSubTypeMatches(MediaTypeInterface $mediaType) |
|
198 | |||
199 | /** |
||
200 | * @param MediaTypeInterface $mediaType |
||
201 | * |
||
202 | * @return bool |
||
203 | */ |
||
204 | 21 | private function isSubTypeEquals(MediaTypeInterface $mediaType) |
|
210 | |||
211 | /** |
||
212 | * @param MediaTypeInterface $mediaType |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | 26 | private function isMediaParametersEqual(MediaTypeInterface $mediaType) |
|
246 | |||
247 | /** |
||
248 | * @param MediaTypeInterface $mediaType |
||
249 | * |
||
250 | * @return bool |
||
251 | */ |
||
252 | 26 | private function bothMediaTypeParamsEmpty(MediaTypeInterface $mediaType) |
|
256 | |||
257 | /** |
||
258 | * @param MediaTypeInterface $mediaType |
||
259 | * |
||
260 | * @return bool |
||
261 | */ |
||
262 | 10 | private function bothMediaTypeParamsNotEmptyAndEqualInSize(MediaTypeInterface $mediaType) |
|
269 | |||
270 | /** |
||
271 | * @param string $name |
||
272 | * |
||
273 | * @return bool |
||
274 | */ |
||
275 | 9 | private function isParamCaseInsensitive($name) |
|
279 | |||
280 | /** |
||
281 | * @param string $name |
||
282 | * @param string $value |
||
283 | * @param string $valueToCompare |
||
284 | * |
||
285 | * @return bool |
||
286 | */ |
||
287 | 9 | private function paramValuesEqual($name, $value, $valueToCompare) |
|
294 | } |
||
295 |