1 | <?php |
||
21 | class HeaderBag extends AbstractParameterBag |
||
22 | { |
||
23 | /** |
||
24 | * @var HeaderInterface[] |
||
25 | */ |
||
26 | protected $parameters = array(); |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $sorted = false; |
||
32 | |||
33 | /** |
||
34 | * Build HeaderBag from Server variables ($_SERVER). |
||
35 | * |
||
36 | * @param array $headers |
||
37 | * |
||
38 | * @return HeaderBag |
||
39 | */ |
||
40 | public static function fromServer(array $headers) |
||
69 | |||
70 | /** |
||
71 | * Add sets of header. |
||
72 | * |
||
73 | * @param HeaderInterface[] $headers |
||
74 | * @param bool $replace |
||
75 | * |
||
76 | * @return $this |
||
77 | * |
||
78 | * @throws InvalidArgumentException |
||
79 | */ |
||
80 | public function add(array $headers, $replace = false) |
||
100 | |||
101 | /** |
||
102 | * Set header. |
||
103 | * |
||
104 | * @param HeaderInterface $header |
||
105 | * @param bool $replace |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function set(HeaderInterface $header, $replace = false) |
||
122 | |||
123 | /** |
||
124 | * Check if header exist by header name. |
||
125 | * |
||
126 | * @param string $headerName |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function has($headerName) |
||
134 | |||
135 | /** |
||
136 | * Get first header by header name or return default value if not exist. |
||
137 | * |
||
138 | * @param string $headerName |
||
139 | * @param mixed $default |
||
140 | * |
||
141 | * @return HeaderInterface|null |
||
142 | */ |
||
143 | public function first($headerName, $default = null) |
||
151 | |||
152 | /** |
||
153 | * Get headers by name or return default value if not exist. |
||
154 | * |
||
155 | * @param string $headerName |
||
156 | * @param mixed $default |
||
157 | * |
||
158 | * @return HeaderInterface[]|mixed |
||
159 | */ |
||
160 | public function get($headerName, $default = null) |
||
164 | |||
165 | /** |
||
166 | * Get all headers. |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | public function all() |
||
176 | |||
177 | /** |
||
178 | * Get all header names. |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | public function keys() |
||
197 | |||
198 | /** |
||
199 | * Remove header by header name. |
||
200 | * |
||
201 | * @param string $headerName |
||
202 | * |
||
203 | * @return $this |
||
204 | */ |
||
205 | public function remove($headerName) |
||
209 | |||
210 | /** |
||
211 | * Cast HeaderBag to string representation. |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | public function __toString() |
||
225 | |||
226 | /** |
||
227 | * Sort headers by name. |
||
228 | */ |
||
229 | private function sort() |
||
236 | } |
||
237 |