@@ -1347,6 +1347,8 @@ public function setFormat($format, $mimeTypes)
1347
1347
* * _format request attribute
1348
1348
* * $default
1349
1349
*
1350
+ * @see getPreferredFormat
1351
+ *
1350
1352
* @param string|null $default The default format
1351
1353
*
1352
1354
* @return string|null The request format
@@ -1563,19 +1565,26 @@ public function isNoCache()
1563
1565
return $ this ->headers ->hasCacheControlDirective ('no-cache ' ) || 'no-cache ' == $ this ->headers ->get ('Pragma ' );
1564
1566
}
1565
1567
1568
+ /**
1569
+ * Gets the preferred format for the response by inspecting, in the following order:
1570
+ * * the request format set using setRequestFormat
1571
+ * * the values of the Accept HTTP header
1572
+ * * the content type of the body of the request
1573
+ */
1566
1574
public function getPreferredFormat (?string $ default = 'html ' ): ?string
1567
1575
{
1568
1576
if (null !== $ this ->preferredFormat ) {
1569
1577
return $ this ->preferredFormat ;
1570
1578
}
1571
1579
1580
+ $ preferredFormat = null ;
1572
1581
foreach ($ this ->getAcceptableContentTypes () as $ contentType ) {
1573
- if ($ this -> preferredFormat = $ this ->getFormat ($ contentType )) {
1574
- return $ this -> preferredFormat ;
1582
+ if ($ preferredFormat = $ this ->getFormat ($ contentType )) {
1583
+ break ;
1575
1584
}
1576
1585
}
1577
1586
1578
- $ this ->preferredFormat = $ this ->getRequestFormat ($ this ->getContentType ());
1587
+ $ this ->preferredFormat = $ this ->getRequestFormat ($ preferredFormat ?: $ this ->getContentType ());
1579
1588
1580
1589
return $ this ->preferredFormat ?: $ default ;
1581
1590
}
0 commit comments