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 = null; |
||
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 const PARAMETER_NAMES = [ |
||
53 | 'charset' => true, |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * @param string $type |
||
58 | * @param string $subType |
||
59 | * @param array<string,string>|null $parameters |
||
60 | */ |
||
61 | 42 | public function __construct(string $type, string $subType, array $parameters = null) |
|
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | 38 | public function getType(): string |
|
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | 38 | public function getSubType(): string |
|
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | 35 | public function getMediaType(): string |
|
105 | |||
106 | /** |
||
107 | * @inheritdoc |
||
108 | */ |
||
109 | 19 | public function getParameters(): ?array |
|
113 | |||
114 | /** |
||
115 | * @inheritdoc |
||
116 | */ |
||
117 | 2 | public function matchesTo(MediaTypeInterface $mediaType): bool |
|
124 | |||
125 | /** |
||
126 | * @inheritdoc |
||
127 | */ |
||
128 | 1 | public function equalsTo(MediaTypeInterface $mediaType): bool |
|
135 | |||
136 | /** |
||
137 | * @param MediaTypeInterface $mediaType |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | 2 | private function isTypeMatches(MediaTypeInterface $mediaType): bool |
|
145 | |||
146 | /** |
||
147 | * @param MediaTypeInterface $mediaType |
||
148 | * |
||
149 | * @return bool |
||
150 | */ |
||
151 | 3 | private function isTypeEquals(MediaTypeInterface $mediaType): bool |
|
157 | |||
158 | /** |
||
159 | * @param MediaTypeInterface $mediaType |
||
160 | * |
||
161 | * @return bool |
||
162 | */ |
||
163 | 2 | private function isSubTypeMatches(MediaTypeInterface $mediaType): bool |
|
167 | |||
168 | /** |
||
169 | * @param MediaTypeInterface $mediaType |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | 3 | private function isSubTypeEquals(MediaTypeInterface $mediaType): bool |
|
179 | |||
180 | /** |
||
181 | * @param MediaTypeInterface $mediaType |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | 3 | private function isMediaParametersEqual(MediaTypeInterface $mediaType): bool |
|
215 | |||
216 | /** |
||
217 | * @param MediaTypeInterface $mediaType |
||
218 | * |
||
219 | * @return bool |
||
220 | */ |
||
221 | 3 | private function bothMediaTypeParamsEmpty(MediaTypeInterface $mediaType): bool |
|
225 | |||
226 | /** |
||
227 | * @param MediaTypeInterface $mediaType |
||
228 | * |
||
229 | * @return bool |
||
230 | */ |
||
231 | 2 | private function bothMediaTypeParamsNotEmptyAndEqualInSize(MediaTypeInterface $mediaType): bool |
|
238 | |||
239 | /** |
||
240 | * @param string $name |
||
241 | * |
||
242 | * @return bool |
||
243 | */ |
||
244 | 2 | private function isParamCaseInsensitive(string $name): bool |
|
248 | |||
249 | /** |
||
250 | * @param string $name |
||
251 | * @param string $value |
||
252 | * @param string $valueToCompare |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | 2 | private function paramValuesEqual(string $name, string $value, string $valueToCompare): bool |
|
263 | } |
||
264 |