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