Skip to content

Commit

Permalink
Eliminate property $beInherited
Browse files Browse the repository at this point in the history
Use local variable instead
  • Loading branch information
Gasol Wu authored and staabm committed Mar 18, 2019
1 parent 7ec94d9 commit d9a1ee7
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -417,16 +417,19 @@ 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];
} else {
$headers = [];
}
$response = $this->parseCurlResponse($headers, $response, $curlHandle);
} else {
$response = $this->parseCurlResult($response, $curlHandle);
}

return $response;
Expand Down

0 comments on commit d9a1ee7

Please sign in to comment.