Skip to content

Commit f9143f0

Browse files
committed
Suggested changes implmented
1 parent eaf50eb commit f9143f0

File tree

1 file changed

+19
-14
lines changed
  • lib/internal/Magento/Framework/View/Element/UiComponent

1 file changed

+19
-14
lines changed

lib/internal/Magento/Framework/View/Element/UiComponent/Context.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,13 @@ protected function setAcceptType()
349349
{
350350
$this->acceptType = 'html';
351351

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) {
355355
$this->acceptType = 'json';
356-
} elseif (strpos($key, 'html') !== false) {
356+
} elseif (strpos($acceptType, 'html') !== false) {
357357
$this->acceptType = 'html';
358-
} elseif (strpos($key, 'xml') !== false) {
358+
} elseif (strpos($acceptType, 'xml') !== false) {
359359
$this->acceptType = 'xml';
360360
}
361361
break;
@@ -419,19 +419,24 @@ public function getUiComponentFactory()
419419
*/
420420
private function getSortedAcceptHeader()
421421
{
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) {
426426
// the default quality is 1.
427427
$q = 1;
428428
// 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;
431437
}
432-
$AcceptTypes[$a] = $q;
433438
}
434-
arsort($AcceptTypes);
435-
return $AcceptTypes;
439+
krsort($acceptTypes);
440+
return array_values($acceptTypes);
436441
}
437442
}

0 commit comments

Comments
 (0)