Total Complexity | 7 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
5 | final class HeaderSet implements \IteratorAggregate |
||
6 | { |
||
7 | private $keyMap; |
||
8 | private $values; |
||
9 | |||
10 | public function __construct(array $headers = []) |
||
11 | { |
||
12 | foreach ($headers as $name => $value) { |
||
13 | $this->setHeader($name, $value); |
||
14 | } |
||
15 | } |
||
16 | |||
17 | public function getIterator(): \Iterator |
||
18 | { |
||
19 | return new \ArrayIterator($this->values); |
||
20 | } |
||
21 | |||
22 | public function setHeader(string $name, string $value) |
||
23 | { |
||
24 | $key = \strtolower($name); |
||
25 | $name = $this->keyMap[$key] ?? $name; |
||
26 | |||
27 | $this->values[$name] = $value; |
||
28 | $this->keyMap[$key] = $name; |
||
29 | } |
||
30 | |||
31 | public function getHeader(string $name) |
||
32 | { |
||
33 | return $this->values[$this->keyMap[\strtolower($name)]] ?? null; |
||
34 | } |
||
35 | |||
36 | public function containsHeader(string $name): bool |
||
39 | } |
||
40 | |||
41 | public function removeHeader(string $name) |
||
42 | { |
||
43 | $key = \strtolower($name); |
||
49 |