@@ -349,13 +349,13 @@ protected function setAcceptType()
349
349
{
350
350
$ this ->acceptType = 'html ' ;
351
351
352
- $ AcceptTypes = $ this ->getSortedAcceptHeader ();
353
- foreach (array_keys ( $ AcceptTypes ) as $ key ) {
354
- if (strpos ($ key , 'json ' ) !== false ) {
352
+ $ acceptTypes = $ this ->getSortedAcceptHeader ();
353
+ foreach ($ acceptTypes as $ acceptType ) {
354
+ if (strpos ($ acceptType , 'json ' ) !== false ) {
355
355
$ this ->acceptType = 'json ' ;
356
- } elseif (strpos ($ key , 'html ' ) !== false ) {
356
+ } elseif (strpos ($ acceptType , 'html ' ) !== false ) {
357
357
$ this ->acceptType = 'html ' ;
358
- } elseif (strpos ($ key , 'xml ' ) !== false ) {
358
+ } elseif (strpos ($ acceptType , 'xml ' ) !== false ) {
359
359
$ this ->acceptType = 'xml ' ;
360
360
}
361
361
break ;
@@ -419,19 +419,24 @@ public function getUiComponentFactory()
419
419
*/
420
420
private function getSortedAcceptHeader ()
421
421
{
422
- $ AcceptTypes = [];
423
- $ rawAcceptType = $ this ->request ->getHeader ('Accept ' );
424
- $ accept = explode (', ' , $ rawAcceptType );
425
- foreach ($ accept as $ a ) {
422
+ $ acceptTypes = [];
423
+ $ acceptHeader = $ this ->request ->getHeader ('Accept ' );
424
+ $ contentTypes = explode (', ' , $ acceptHeader );
425
+ foreach ($ contentTypes as $ contentType ) {
426
426
// the default quality is 1.
427
427
$ q = 1 ;
428
428
// check if there is a different quality
429
- if (strpos ($ a , ';q= ' ) !== false ) {
430
- list ($ a , $ q ) = explode (';q= ' , $ a );
429
+ if (strpos ($ contentType , ';q= ' ) !== false ) {
430
+ list ($ contentType , $ q ) = explode (';q= ' , $ contentType );
431
+ }
432
+
433
+ if (array_key_exists ($ q , $ acceptTypes )) {
434
+ $ acceptTypes [$ q ] = $ acceptTypes [$ q ] . ', ' . $ contentType ;
435
+ } else {
436
+ $ acceptTypes [$ q ] = $ contentType ;
431
437
}
432
- $ AcceptTypes [$ a ] = $ q ;
433
438
}
434
- arsort ( $ AcceptTypes );
435
- return $ AcceptTypes ;
439
+ krsort ( $ acceptTypes );
440
+ return array_values ( $ acceptTypes ) ;
436
441
}
437
442
}
0 commit comments