File tree 2 files changed +5
-10
lines changed
src/Symfony/Component/HttpFoundation
2 files changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -1586,20 +1586,17 @@ public function isNoCache()
1586
1586
*/
1587
1587
public function getPreferredFormat (?string $ default = 'html ' ): ?string
1588
1588
{
1589
- if (null !== $ this ->preferredFormat ) {
1589
+ if (null !== $ this ->preferredFormat || null !== $ this -> preferredFormat = $ this -> getRequestFormat ( null ) ) {
1590
1590
return $ this ->preferredFormat ;
1591
1591
}
1592
1592
1593
- $ preferredFormat = null ;
1594
- foreach ($ this ->getAcceptableContentTypes () as $ contentType ) {
1595
- if ($ preferredFormat = $ this ->getFormat ($ contentType )) {
1596
- break ;
1593
+ foreach ($ this ->getAcceptableContentTypes () as $ mimeType ) {
1594
+ if ($ this ->preferredFormat = $ this ->getFormat ($ mimeType )) {
1595
+ return $ this ->preferredFormat ;
1597
1596
}
1598
1597
}
1599
1598
1600
- $ this ->preferredFormat = $ this ->getRequestFormat ($ preferredFormat ?: $ this ->getContentType ());
1601
-
1602
- return $ this ->preferredFormat ?: $ default ;
1599
+ return $ default ;
1603
1600
}
1604
1601
1605
1602
/**
Original file line number Diff line number Diff line change @@ -408,12 +408,10 @@ public function testGetPreferredFormat()
408
408
409
409
$ request ->setRequestFormat ('atom ' );
410
410
$ request ->headers ->set ('Accept ' , 'application/ld+json ' );
411
- $ request ->headers ->set ('Content-Type ' , 'application/merge-patch+json ' );
412
411
$ this ->assertSame ('atom ' , $ request ->getPreferredFormat ());
413
412
414
413
$ request = new Request ();
415
414
$ request ->headers ->set ('Accept ' , 'application/xml ' );
416
- $ request ->headers ->set ('Content-Type ' , 'application/json ' );
417
415
$ this ->assertSame ('xml ' , $ request ->getPreferredFormat ());
418
416
419
417
$ request = new Request ();
You can’t perform that action at this time.
0 commit comments