1: <?php
2: namespace Worldline\Acquiring\Sdk\Communication;
3:
4: /**
5: * Class ResponseHeaderBuilder
6: *
7: * @package Worldline\Acquiring\Sdk\Communication
8: */
9: class ResponseHeaderBuilder
10: {
11: /** @var string */
12: private $headerString = '';
13:
14: /** @var array|null */
15: private $headers = null;
16:
17: /** @var string|null */
18: private $contentType = null;
19:
20: /**
21: * @param string $data
22: */
23: public function append($data)
24: {
25: $this->headerString .= $data;
26: $this->headers = null;
27: }
28:
29: /**
30: * @return array
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: * @return string|null
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: