Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/Symfony/Component/HttpFoundation/AcceptHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ public function __construct(array $items)
*/
public static function fromString(?string $headerValue): self
{
$parts = HeaderUtils::split($headerValue ?? '', ',;=');
$items = [];
foreach (HeaderUtils::split($headerValue ?? '', ',;=') as $i => $parts) {
$part = array_shift($parts);
$item = new AcceptHeaderItem($part[0], HeaderUtils::combine($parts));

return new self(array_map(function ($subParts) {
static $index = 0;
$part = array_shift($subParts);
$attributes = HeaderUtils::combine($subParts);

$item = new AcceptHeaderItem($part[0], $attributes);
$item->setIndex($index++);
$items[] = $item->setIndex($i);
}

return $item;
}, $parts));
return new self($items);
}

/**
Expand Down Expand Up @@ -95,10 +92,11 @@ public function get(string $value): ?AcceptHeaderItem
return null;
}

usort($candidates, fn ($a, $b) =>
$this->getSpecificity($b, $queryItem) <=> $this->getSpecificity($a, $queryItem) // Descending specificity
?: $b->getQuality() <=> $a->getQuality() // Descending quality
?: $a->getIndex() <=> $b->getIndex() // Ascending index (stability)
usort(
$candidates,
fn ($a, $b) => $this->getSpecificity($b, $queryItem) <=> $this->getSpecificity($a, $queryItem) // Descending specificity
?: $b->getQuality() <=> $a->getQuality() // Descending quality
?: $a->getIndex() <=> $b->getIndex() // Ascending index (stability)
);

return reset($candidates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

try {
$r->headers->setCookie(new Cookie('Hello + world', 'hodor', 0, null, null, null, false, true));
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
echo $e->getMessage();
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ protected function tearDown(): void
{
Request::setTrustedProxies([], -1);
Request::setTrustedHosts([]);
Request::setFactory(null);
\Closure::bind(static fn () => self::$formats = null, null, Request::class)();
}

public function testInitialize()
Expand Down
Loading