curlFactory = $curlFactory; $this->responseFactory = $responseFactory; $this->converter = $converter; $this->logger = $logger; } /** * {@inheritdoc} */ public function request($method, $url, array $body = [], array $headers = [], $version = '1.1') { $response = new \Zend_Http_Response(0, []); try { $curl = $this->curlFactory->create(); $headers = $this->applyContentTypeHeaderFromConverter($headers); $curl->write($method, $url, $version, $headers, $this->converter->toBody($body)); $result = $curl->read(); if ($curl->getErrno()) { $this->logger->critical( new \Exception( sprintf( 'MBI service CURL connection error #%s: %s', $curl->getErrno(), $curl->getError() ) ) ); return $response; } $response = $this->responseFactory->create($result); } catch (\Exception $e) { $this->logger->critical($e); } return $response; } /** * @param array $headers * * @return array */ private function applyContentTypeHeaderFromConverter(array $headers) { $contentTypeHeaderKey = array_search($this->converter->getContentTypeHeader(), $headers); if ($contentTypeHeaderKey === false) { $headers[] = $this->converter->getContentTypeHeader(); } return $headers; } }