1 | <?php |
||
9 | class Headers implements Arrayable, \Iterator { |
||
10 | |||
11 | /** @var Map */ |
||
12 | private $headers; |
||
13 | |||
14 | 7 | public function __construct($contents = []) { |
|
15 | 7 | $this->parse($contents === null ? [] : $contents); |
|
16 | 7 | } |
|
17 | |||
18 | 7 | private function parse($contents) { |
|
19 | 7 | $data = CollectionUtils::toMap($contents); |
|
20 | |||
21 | // headers |
||
22 | 7 | $this->headers = new Map(); |
|
23 | 7 | foreach ($data as $h => $props) { |
|
24 | 1 | $this->headers->set($h, new Header($h, $props)); |
|
25 | 7 | } |
|
26 | 7 | } |
|
27 | |||
28 | 6 | public function toArray() { |
|
31 | |||
32 | 1 | public function size() { |
|
35 | |||
36 | /** |
||
37 | * Returns whether a header with the given name exists |
||
38 | * |
||
39 | * @param string $header |
||
40 | * @return boolean |
||
41 | */ |
||
42 | 1 | public function has($header) { |
|
45 | |||
46 | /** |
||
47 | * Returns whether the given header exists |
||
48 | * |
||
49 | * @param Header $header |
||
50 | * @return boolean |
||
51 | */ |
||
52 | 1 | public function contains(Header $header) { |
|
55 | |||
56 | /** |
||
57 | * Returns the header info for the given code |
||
58 | * |
||
59 | * @param string $header |
||
60 | * @return Header |
||
61 | */ |
||
62 | 1 | public function get($header) { |
|
65 | |||
66 | /** |
||
67 | * Sets the header |
||
68 | * |
||
69 | * @param Header $header |
||
70 | */ |
||
71 | 1 | public function add(Header $header) { |
|
74 | |||
75 | /** |
||
76 | * Removes the given header |
||
77 | * |
||
78 | * @param string $header |
||
79 | */ |
||
80 | 1 | public function remove($header) { |
|
83 | |||
84 | public function current() { |
||
85 | return $this->headers->current(); |
||
87 | |||
88 | public function key() { |
||
91 | |||
92 | public function next() { |
||
95 | |||
96 | public function rewind() { |
||
99 | |||
100 | public function valid() { |
||
103 | } |
||
104 |