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 committed Dec 14, 2018
1 parent b9db9f2 commit 0f657da
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ 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) {
if ($separatedHeaders) {
$this->curlSettings[CURLOPT_HEADER] = true;
} else {
$this->curlSettings[CURLOPT_HEADERFUNCTION] = [$this, 'receiveCurlHeader'];
Expand Down Expand Up @@ -418,16 +418,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 0f657da

Please sign in to comment.