From d9a1ee76df364aeba7195e3475f693140cac8ceb Mon Sep 17 00:00:00 2001 From: Gasol Wu Date: Fri, 14 Dec 2018 11:16:27 +0800 Subject: [PATCH] Eliminate property $beInherited Use local variable instead --- lib/Client.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/Client.php b/lib/Client.php index d4df42e..88a2599 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -68,24 +68,24 @@ class Client extends EventEmitter protected $headerLinesMap = []; - protected $beInherited; - /** * Initializes the client. */ public function __construct() { - $this->beInherited = __CLASS__ !== get_class($this); + // See https://github.com/sabre-io/http/pull/115#discussion_r241292068 + // Preserve compatibility for sub-classes that implements their own method `parseCurlResult` + $separatedHeaders = __CLASS__ === get_class($this); $this->curlSettings = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_NOBODY => false, CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', ]; - if ($this->beInherited) { - $this->curlSettings[CURLOPT_HEADER] = true; - } else { + if ($separatedHeaders) { $this->curlSettings[CURLOPT_HEADERFUNCTION] = [$this, 'receiveCurlHeader']; + } else { + $this->curlSettings[CURLOPT_HEADER] = true; } } @@ -417,9 +417,10 @@ protected function createCurlSettingsArray(RequestInterface $request): array private function parseResponse(string $response, $curlHandle): array { - if ($this->beInherited) { - $response = $this->parseCurlResult($response, $curlHandle); - } else { + $settings = $this->curlSettings; + $separatedHeaders = isset($settings[CURLOPT_HEADERFUNCTION]) && (bool) $settings[CURLOPT_HEADERFUNCTION]; + + if ($separatedHeaders) { $resourceId = (int) $curlHandle; if (isset($this->headerLinesMap[$resourceId])) { $headers = $this->headerLinesMap[$resourceId]; @@ -427,6 +428,8 @@ private function parseResponse(string $response, $curlHandle): array $headers = []; } $response = $this->parseCurlResponse($headers, $response, $curlHandle); + } else { + $response = $this->parseCurlResult($response, $curlHandle); } return $response;