1 | <?php |
||
20 | class Response extends AbstractResponse |
||
21 | { |
||
22 | protected $rawData; |
||
23 | |||
24 | protected $headers; |
||
25 | |||
26 | protected $statusCode; |
||
27 | |||
28 | protected $reasonPhrase; |
||
29 | |||
30 | 2 | public function __construct(Request $request, $rawData, array $rawHeaders) |
|
36 | |||
37 | 2 | public function getRawData() |
|
41 | |||
42 | 2 | public function getHeader($name) |
|
48 | |||
49 | public function getHeaders() |
||
53 | |||
54 | 2 | public function parseHeaders($headers) |
|
55 | { |
||
56 | 2 | $result = []; |
|
57 | |||
58 | 2 | foreach ($headers as $header) { |
|
59 | 2 | if (strncmp($header, 'HTTP/', 5) === 0) { |
|
60 | 2 | $parts = explode(' ', $header, 3); |
|
61 | 2 | $this->version = substr($parts[0], 5); |
|
|
|||
62 | 2 | $this->statusCode = $parts[1]; |
|
63 | 2 | $this->reasonPhrase = $parts[2]; |
|
64 | 2 | } elseif (($pos = strpos($header, ':')) !== false) { |
|
65 | 2 | $name = strtolower(trim(substr($header, 0, $pos))); |
|
66 | 2 | $value = trim(substr($header, $pos + 1)); |
|
67 | 2 | $result[$name][] = $value; |
|
68 | } else { |
||
69 | 2 | $result['raw'][] = $header; |
|
70 | } |
||
71 | } |
||
72 | |||
73 | 2 | return $result; |
|
74 | } |
||
75 | |||
76 | 2 | public function getStatusCode() |
|
80 | |||
81 | public function getReasonPhrase() |
||
85 | } |
||
86 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: