*/ class AcceptHeader { /** @var AcceptHeaderItem[] */ private array $items = []; private bool $sorted = true; /** * @param AcceptHeaderItem[] $items */ public function __construct(array $items) { foreach ($items as $item) { $this->add($item); } } /** * Builds an AcceptHeader instance from a string. */ public static function fromString(?string $headerValue): self { $index = 0; $parts = HeaderUtils::split($headerValue ?? '', ',;='); return new self(array_map(function ($subParts) use (&$index) { $part = array_shift($subParts); $attributes = HeaderUtils::combine($subParts); $item = new AcceptHeaderItem($part[0], $attributes); $item->setIndex($index++); return $item; }, $parts)); } /** * Returns header value's string representation. */ public function __toString(): string { return implode(',', $this->items); } /** * Tests if header has given value. */ public function has(string $value): bool { return isset($this->items[$value]); } /** * Returns given value's item, if exists. */ public function get(string $value): ?AcceptHeaderItem { return $this->items[$value] ?? $this->items[explode('/', $value)[0].'/*'] ?? $this->items['*/*'] ?? $this->items['*'] ?? null; } /** * Adds an item. * * @return $this */ public function add(AcceptHeaderItem $item): static { $this->items[$item->getValue()] = $item; $this->sorted = false; return $this; } /** * Returns all items. * * @return AcceptHeaderItem[] */ public function all(): array { $this->sort(); return $this->items; } /** * Filters items on their value using given regex. */ public function filter(string $pattern): self { return new self(array_filter($this->items, function (AcceptHeaderItem $item) use ($pattern) { return preg_match($pattern, $item->getValue()); })); } /** * Returns first item. */ public function first(): ?AcceptHeaderItem { $this->sort(); return !empty($this->items) ? reset($this->items) : null; } /** * Sorts items by descending quality. */ private function sort(): void { if (!$this->sorted) { uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) { $qA = $a->getQuality(); $qB = $b->getQuality(); if ($qA === $qB) { return $a->getIndex() > $b->getIndex() ? 1 : -1; } return $qA > $qB ? -1 : 1; }); $this->sorted = true; } } } __halt_compiler();----SIGNATURE:----G4Z9mDpR6WQL4VWGxPnfpXqaMj4/YuEPm4uVhJqDMiDq4+Ncpq/UVbHZrwuzPkYJIW0jqfHz5QdC0bCH6q0ymkOt94oscyE1iHx44dZXO2/kc0gNJhtercJm4WIw1YlwzLK5TMZ790xG5nNFa3FD/1jtx2CNJYKY9YPvkcQ2/QuV1x19BKrJbavm76uwX9j1M94q7IwaHdPFRWn7ewx9z5IZPGSM18T/C36xurYspjbwxYBtsDiqg7HEAXLW0peyZgUUq/eyBvPgevOY+s7XG0sJK20zmZm/HC24xVdiaO26f6HLukykY0wlvXA08IXWpI7s6GrB25KGXovMm1ueyUKxoCzRJINxv74L/4RCkA08KxxtJhtV+kYh1q/+QWIwYNOhOi0UUVOGM6d0GxH6iyLux5b71f9Bs6+TfQefrKHO52SvIPG4UAwwgQ6VEIda1091pywlUNCYVq3Ja+I2qrHIqXdrFPFFIbhoTRM01oXdMgkg5zBd41s+2hhH5XEHF8Lj3zbUY3sFTHjjciRRk/PTQwc/QbNaxr1RAApDNSVGg0Z8a1DGUxSvflpWHrnG8fW/ndWFhi4z24DMvCfZFmD8q6E7yd2F03gkyGHZhL3ytctSm5ytbg/QyzE+Fzd6eJOXwv3szMemheAJEXEUyZ/I3fNRLjAcBr4wQIlBGTI=----ATTACHMENT:----NDgxMDc1MDg0ODk3ODI5NCA2ODE2Mjg3NTU4MjIxMTE5IDI1MjAwOTI1MzU4MjQyNjQ=