1 | <?php |
||
8 | class Message implements MessageInterface |
||
9 | { |
||
10 | protected $_protocolVersion = '1.1'; |
||
11 | |||
12 | protected $_headers = []; |
||
13 | |||
14 | protected $_body; |
||
15 | |||
16 | /** |
||
17 | * @var array The headers which are accepted. |
||
18 | */ |
||
19 | protected $_validHeaders = [ |
||
20 | 'Content-Type', |
||
21 | 'Connection', |
||
22 | 'Accept', |
||
23 | 'Accept-Encoding', |
||
24 | 'Accept-Language', |
||
25 | 'Cache-Control', |
||
26 | 'Cookie', |
||
27 | 'Host', |
||
28 | 'User-Agent', |
||
29 | 'Remote Address', |
||
30 | // ... |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * @var array Valid/Supported HTTP Protocol versions . |
||
35 | */ |
||
36 | protected $_validVersions = [ |
||
37 | '1.0', |
||
38 | '1.1', |
||
39 | '2.0', |
||
40 | ]; |
||
41 | |||
42 | |||
43 | public function __construct(StreamInterface $stream = null) |
||
52 | |||
53 | /** |
||
54 | * Returns the message's protocol version. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getProtocolVersion() |
||
62 | |||
63 | /** |
||
64 | * Returns an instance of the message with the specified protocol version. |
||
65 | * |
||
66 | * @param string $version The protocol version. |
||
67 | * @return \Almendra\Http\Psr\Messages\Message |
||
68 | * @throws InvalidArgumentException |
||
69 | */ |
||
70 | public function withProtocolVersion($version) |
||
80 | |||
81 | /** |
||
82 | * Returns the headers. |
||
83 | * |
||
84 | * @return array An associative array of string values. |
||
85 | */ |
||
86 | public function getHeaders() |
||
90 | |||
91 | /** |
||
92 | * Check if a header exists. |
||
93 | * |
||
94 | * @param string $name The name of the header. |
||
95 | * @return boolean |
||
96 | */ |
||
97 | public function hasHeader($name) |
||
105 | |||
106 | /** |
||
107 | * Checks if a key name exists in a given array using a case-insensitive string comparision. |
||
108 | * |
||
109 | * @param string $name The key name |
||
110 | * @param array $values The array of values |
||
111 | * @return boolean |
||
112 | */ |
||
113 | protected function isArrayKeyLowercase($name, array $values) |
||
125 | |||
126 | /** |
||
127 | * Returns a header. |
||
128 | * |
||
129 | * @param string $name The header's name. |
||
130 | * @return array |
||
131 | */ |
||
132 | public function getHeader($name) |
||
143 | |||
144 | /** |
||
145 | * Returns a comma-separated header. |
||
146 | * |
||
147 | * @param string $name The header's name. |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getHeaderLine($name) |
||
164 | |||
165 | /** |
||
166 | * Returns a message instance with the specified header |
||
167 | * Replaces the header if it exists. |
||
168 | * |
||
169 | * @param string $name The header's name |
||
170 | * @param string $value The header's value |
||
171 | * @return \Almendra\Http\Psr\Messages\Message |
||
172 | */ |
||
173 | public function withHeader($name, $value) |
||
184 | |||
185 | /** |
||
186 | * Returns a message instance with the an added header. |
||
187 | * Does not replace the it if it exists already. |
||
188 | * |
||
189 | * @param string $name The header's name |
||
190 | * @param string $value The header's value |
||
191 | * @return \Almendra\Http\Psr\Messages\Message |
||
192 | */ |
||
193 | public function withAddedHeader($name, $value) |
||
207 | |||
208 | /** |
||
209 | * Checks whather a header is valid. |
||
210 | * |
||
211 | * @param string $name The header's name |
||
212 | * @return boolean true if supported |
||
213 | */ |
||
214 | public function isHeaderValid($name) |
||
225 | |||
226 | /** |
||
227 | * Sets a header, by name. |
||
228 | * |
||
229 | * @param string $name The header's name |
||
230 | * @param string $name The header's value |
||
231 | * @return void |
||
232 | * @throws \InvalidArgumentException ! |
||
233 | */ |
||
234 | public function setHeader($name, $value) |
||
246 | |||
247 | /** |
||
248 | * Adds a header. Does not replace the value if it already exists. |
||
249 | * |
||
250 | * @param string $name The header's name |
||
251 | * @param mixed $value The header's value |
||
252 | * @return void |
||
253 | */ |
||
254 | public function addHeader($name, $value) |
||
263 | |||
264 | /** |
||
265 | * Returns an instance of the message without the specified header. |
||
266 | * |
||
267 | * @param string $name The header's name |
||
268 | * @return \Almendra\Http\Psr\Messages\Message |
||
269 | */ |
||
270 | public function withoutHeader($name) |
||
279 | |||
280 | /** |
||
281 | * Unsets a header. |
||
282 | * |
||
283 | * @param string $name The header's name. |
||
284 | * @return void |
||
285 | */ |
||
286 | public function unsetHeader($name) |
||
290 | |||
291 | /** |
||
292 | * Returns the message's body. |
||
293 | * |
||
294 | * @return Psr\Http\Message\StreamInterface |
||
295 | */ |
||
296 | public function getBody() |
||
300 | |||
301 | /** |
||
302 | * Returns an instance of the message with the specified body. |
||
303 | * |
||
304 | * @param \Psr\Http\Message\StreamInterface $body The body to be added |
||
305 | * @return \Almendra\Http\Psr\Messages\Message |
||
306 | * @throws \InvalidArgumentException |
||
307 | */ |
||
308 | public function withBody(StreamInterface $body) |
||
315 | } |
||
316 |
This check looks for function calls that miss required arguments.