1: | <?php |
2: | namespace Worldline\Connect\Sdk\Communication; |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | class ResponseHeaderBuilder |
10: | { |
11: | |
12: | private $headerString = ''; |
13: | |
14: | |
15: | private $headers = null; |
16: | |
17: | |
18: | private $contentType = null; |
19: | |
20: | |
21: | |
22: | |
23: | public function append($data) |
24: | { |
25: | $this->headerString .= $data; |
26: | $this->headers = null; |
27: | } |
28: | |
29: | |
30: | |
31: | |
32: | public function getHeaders() |
33: | { |
34: | if (is_null($this->headers)) { |
35: | $this->headers = HttpHeaderHelper::parseRawHeaders(explode("\r\n", $this->headerString)); |
36: | } |
37: | return $this->headers; |
38: | } |
39: | |
40: | |
41: | |
42: | |
43: | public function getContentType() |
44: | { |
45: | if (is_null($this->contentType)) { |
46: | $headers = $this->getHeaders(); |
47: | foreach ($headers as $headerKey => $headerValue) { |
48: | if (strtolower($headerKey) === 'content-type') { |
49: | $this->contentType = $headerValue; |
50: | break; |
51: | } |
52: | } |
53: | } |
54: | return $this->contentType; |
55: | } |
56: | } |
57: | |