|
1
|
|
|
<?php |
|
2
|
|
|
namespace gossi\swagger\collections; |
|
3
|
|
|
|
|
4
|
|
|
use gossi\swagger\Header; |
|
5
|
|
|
use phootwork\collection\CollectionUtils; |
|
6
|
|
|
use phootwork\collection\Map; |
|
7
|
|
|
use phootwork\lang\Arrayable; |
|
8
|
|
|
|
|
9
|
|
|
class Headers implements Arrayable, \Iterator { |
|
10
|
|
|
|
|
11
|
|
|
/** @var Map */ |
|
12
|
|
|
private $headers; |
|
13
|
|
|
|
|
14
|
6 |
|
public function __construct($contents = []) { |
|
15
|
6 |
|
$this->parse($contents === null ? [] : $contents); |
|
16
|
6 |
|
} |
|
17
|
|
|
|
|
18
|
6 |
|
private function parse($contents) { |
|
19
|
6 |
|
$data = CollectionUtils::toMap($contents); |
|
20
|
|
|
|
|
21
|
|
|
// headers |
|
22
|
6 |
|
$this->headers = new Map(); |
|
23
|
6 |
|
foreach ($data as $h => $props) { |
|
24
|
1 |
|
$this->headers->set($h, new Header($h, $props)); |
|
25
|
6 |
|
} |
|
26
|
6 |
|
} |
|
27
|
|
|
|
|
28
|
5 |
|
public function toArray() { |
|
29
|
5 |
|
return $this->headers->toArray(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function size() { |
|
33
|
1 |
|
return $this->headers->size(); |
|
34
|
|
|
} |
|
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) { |
|
43
|
1 |
|
return $this->headers->has($header); |
|
44
|
|
|
} |
|
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) { |
|
53
|
1 |
|
return $this->headers->contains($header); |
|
54
|
|
|
} |
|
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) { |
|
63
|
1 |
|
return $this->headers->get($header); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Sets the header |
|
68
|
|
|
* |
|
69
|
|
|
* @param Header $header |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function add(Header $header) { |
|
72
|
1 |
|
$this->headers->set($header->getHeader(), $header); |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Removes the given header |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $header |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function remove($header) { |
|
81
|
1 |
|
$this->headers->remove($header); |
|
82
|
1 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function current() { |
|
85
|
|
|
return $this->headers->current(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function key() { |
|
89
|
|
|
return $this->headers->key(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function next() { |
|
93
|
|
|
return $this->headers->next(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function rewind() { |
|
97
|
|
|
return $this->headers->rewind(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function valid() { |
|
101
|
|
|
return $this->headers->valid(); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|