1 | <?php |
||
14 | class Headers |
||
15 | { |
||
16 | /** |
||
17 | * List of headers name that should not be normalized. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | private $ignoreProcessing = [ |
||
22 | "user-agent" => true |
||
23 | ]; |
||
24 | |||
25 | /** |
||
26 | * Header data |
||
27 | * |
||
28 | * @var array|null |
||
29 | */ |
||
30 | private $data; |
||
31 | |||
32 | /** |
||
33 | * Constructor |
||
34 | * |
||
35 | * @param array|null $headers |
||
36 | * |
||
37 | */ |
||
38 | 43 | public function __construct( |
|
47 | |||
48 | /** |
||
49 | * Add header value |
||
50 | * If the header already exists data are merged, method DOES NOT replace previous value. |
||
51 | * |
||
52 | * @param string $name Name of the header. |
||
53 | * @param mixed $value Value of the header can be scalar data type or string. |
||
54 | * |
||
55 | * @return void |
||
56 | */ |
||
57 | 2 | public function add($name, $value) |
|
69 | |||
70 | /** |
||
71 | * Set header value |
||
72 | * If the header already exist value will be replaced. |
||
73 | * |
||
74 | * @param string $name Name of the header. |
||
75 | * @param mixed $value Value of the header can be scalar data type or string. |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | 12 | public function set($name, $value) |
|
85 | |||
86 | /** |
||
87 | * Get header by provided name |
||
88 | * |
||
89 | * @param string $name Name of the header. |
||
90 | * |
||
91 | * @return mixed value of header |
||
92 | */ |
||
93 | 7 | public function get($name) |
|
103 | |||
104 | /** |
||
105 | * Get header values separated by comma |
||
106 | * |
||
107 | * @param string $name Name of the header. |
||
108 | * |
||
109 | * @return string value of header separated by comma |
||
110 | */ |
||
111 | 2 | public function getLine($name) |
|
117 | |||
118 | /** |
||
119 | * Get all headers |
||
120 | * |
||
121 | * @return array value of all headers |
||
122 | */ |
||
123 | 8 | public function all() |
|
127 | |||
128 | /** |
||
129 | * Remove header by provided name |
||
130 | * |
||
131 | * @param string $name Name of the header. |
||
132 | * |
||
133 | * @return self |
||
134 | */ |
||
135 | 3 | public function remove($name) |
|
144 | |||
145 | /** |
||
146 | * Check if header exist |
||
147 | * |
||
148 | * @param string $name Name of the header. |
||
149 | * |
||
150 | * @return boolean Returns TRUE if exists or FALSE if not. |
||
151 | */ |
||
152 | 12 | public function exists($name) |
|
156 | |||
157 | // ------------ PRIVATE METHODS |
||
158 | |||
159 | /** |
||
160 | * Normalize headers values |
||
161 | * |
||
162 | * @param array $headers Headers for normalization. |
||
163 | * |
||
164 | * @return array Normalized header data. |
||
165 | */ |
||
166 | 16 | private function normalizeHeaders($headers) |
|
176 | |||
177 | /** |
||
178 | * Normalize header value |
||
179 | * |
||
180 | * @param string $name Name of header - some headers should not be normalized. |
||
181 | * @param string $data Header data for normalization. |
||
182 | * |
||
183 | * @return array Normalized value of header |
||
184 | */ |
||
185 | 15 | private function normalizeData($name, $data) |
|
193 | |||
194 | /** |
||
195 | * Normalize header name |
||
196 | * |
||
197 | * @param string $name Name of header for normalization |
||
198 | * |
||
199 | * @return string Normalized name of header |
||
200 | */ |
||
201 | 25 | private function normalizeName($name) |
|
210 | } |
||
211 |