@@ -195,6 +195,28 @@ class Request
195
195
self ::HEADER_X_FORWARDED_PREFIX => 'X_FORWARDED_PREFIX ' ,
196
196
];
197
197
198
+ /**
199
+ * This mapping is used when no exact MIME match is found in $formats.
200
+ *
201
+ * It enables mappings like application/soap+xml -> xml.
202
+ *
203
+ * @see https://datatracker.ietf.org/doc/html/rfc6839
204
+ * @see https://datatracker.ietf.org/doc/html/rfc7303
205
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
206
+ */
207
+ private const STRUCTURED_SUFFIX_FORMATS = [
208
+ 'json ' => 'json ' ,
209
+ 'xml ' => 'xml ' ,
210
+ 'xhtml ' => 'html ' ,
211
+ 'cbor ' => 'cbor ' ,
212
+ 'zip ' => 'zip ' ,
213
+ 'ber ' => 'asn1 ' ,
214
+ 'der ' => 'asn1 ' ,
215
+ 'tlv ' => 'tlv ' ,
216
+ 'wbxml ' => 'xml ' ,
217
+ 'yaml ' => 'yaml ' ,
218
+ ];
219
+
198
220
private bool $ isIisRewrite = false ;
199
221
200
222
/**
@@ -1239,8 +1261,9 @@ public static function getMimeTypes(string $format): array
1239
1261
* @param string|null $mimeType The mime type to check
1240
1262
* @param bool $subtypeFallback Whether to fall back to the subtype if no exact match is found
1241
1263
*/
1242
- public function getFormat (?string $ mimeType , bool $ subtypeFallback = false ): ?string
1264
+ public function getFormat (?string $ mimeType/* , bool $subtypeFallback = false */ ): ?string
1243
1265
{
1266
+ $ subtypeFallback = 2 <= \func_num_args () ? func_get_arg (1 ) : false ;
1244
1267
$ canonicalMimeType = null ;
1245
1268
if ($ mimeType && false !== $ pos = strpos ($ mimeType , '; ' )) {
1246
1269
$ canonicalMimeType = trim (substr ($ mimeType , 0 , $ pos ));
@@ -1265,8 +1288,8 @@ public function getFormat(?string $mimeType, bool $subtypeFallback = false): ?st
1265
1288
1266
1289
if (str_starts_with ($ canonicalMimeType , 'application/ ' ) && str_contains ($ canonicalMimeType , '+ ' )) {
1267
1290
$ suffix = substr (strrchr ($ canonicalMimeType , '+ ' ), 1 );
1268
- if (isset (static :: getStructuredSuffixFormats () [$ suffix ])) {
1269
- return static :: getStructuredSuffixFormats () [$ suffix ];
1291
+ if (isset (self :: STRUCTURED_SUFFIX_FORMATS [$ suffix ])) {
1292
+ return self :: STRUCTURED_SUFFIX_FORMATS [$ suffix ];
1270
1293
}
1271
1294
}
1272
1295
@@ -1963,32 +1986,6 @@ protected static function initializeFormats(): void
1963
1986
];
1964
1987
}
1965
1988
1966
- /**
1967
- * This mapping is used when no exact MIME match is found in $formats.
1968
- * It enables handling of types like application/soap+xml → 'xml'.
1969
- *
1970
- * @see https://datatracker.ietf.org/doc/html/rfc6839
1971
- * @see https://datatracker.ietf.org/doc/html/rfc7303
1972
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
1973
- *
1974
- * @return array<string, string>
1975
- */
1976
- private static function getStructuredSuffixFormats (): array
1977
- {
1978
- return [
1979
- 'json ' => 'json ' ,
1980
- 'xml ' => 'xml ' ,
1981
- 'xhtml ' => 'html ' ,
1982
- 'cbor ' => 'cbor ' ,
1983
- 'zip ' => 'zip ' ,
1984
- 'ber ' => 'asn1 ' ,
1985
- 'der ' => 'asn1 ' ,
1986
- 'tlv ' => 'tlv ' ,
1987
- 'wbxml ' => 'xml ' ,
1988
- 'yaml ' => 'yaml ' ,
1989
- ];
1990
- }
1991
-
1992
1989
private function setPhpDefaultLocale (string $ locale ): void
1993
1990
{
1994
1991
// if either the class Locale doesn't exist, or an exception is thrown when
0 commit comments