@@ -195,6 +195,28 @@ class Request
195195 self ::HEADER_X_FORWARDED_PREFIX => 'X_FORWARDED_PREFIX ' ,
196196 ];
197197
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+
198220 private bool $ isIisRewrite = false ;
199221
200222 /**
@@ -1239,8 +1261,9 @@ public static function getMimeTypes(string $format): array
12391261 * @param string|null $mimeType The mime type to check
12401262 * @param bool $subtypeFallback Whether to fall back to the subtype if no exact match is found
12411263 */
1242- public function getFormat (?string $ mimeType , bool $ subtypeFallback = false ): ?string
1264+ public function getFormat (?string $ mimeType/* , bool $subtypeFallback = false */ ): ?string
12431265 {
1266+ $ subtypeFallback = 2 <= \func_num_args () ? func_get_arg (1 ) : false ;
12441267 $ canonicalMimeType = null ;
12451268 if ($ mimeType && false !== $ pos = strpos ($ mimeType , '; ' )) {
12461269 $ canonicalMimeType = trim (substr ($ mimeType , 0 , $ pos ));
@@ -1265,8 +1288,8 @@ public function getFormat(?string $mimeType, bool $subtypeFallback = false): ?st
12651288
12661289 if (str_starts_with ($ canonicalMimeType , 'application/ ' ) && str_contains ($ canonicalMimeType , '+ ' )) {
12671290 $ 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 ];
12701293 }
12711294 }
12721295
@@ -1963,32 +1986,6 @@ protected static function initializeFormats(): void
19631986 ];
19641987 }
19651988
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-
19921989 private function setPhpDefaultLocale (string $ locale ): void
19931990 {
19941991 // if either the class Locale doesn't exist, or an exception is thrown when
0 commit comments