Skip to content

Commit

Permalink
client: reorder guzzle version compatibility check (#328)
Browse files Browse the repository at this point in the history
It's an edge case but, if two versions of guzzle is installed at the
same time, reordering and check the presence of
`\GuzzleHttp\Client::createRequest` method avoid errors.
  • Loading branch information
leonampd committed Apr 23, 2019
1 parent f8778ca commit 99f11c7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,18 @@ public function send(RequestInterface $apiRequest)
*/
private function buildRequest($apiRequest)
{
if (class_exists('\\GuzzleHttp\\Message\\Request')) {
if (class_exists('\\GuzzleHttp\\Psr7\\Request')) {
return new \GuzzleHttp\Psr7\Request(
$apiRequest->getMethod(),
$apiRequest->getPath(),
['Content-Type' => 'application/json'],
json_encode($this->buildBody($apiRequest))
);
}

if (class_exists('\\GuzzleHttp\\Message\\Request')
&& method_exists($this->client, 'createRequest')
) {
$options = array_merge(
$this->requestOptions,
['json' => $this->buildBody($apiRequest)]
Expand All @@ -92,15 +103,6 @@ private function buildRequest($apiRequest)
);
}

if (class_exists('\\GuzzleHttp\\Psr7\\Request')) {
return new \GuzzleHttp\Psr7\Request(
$apiRequest->getMethod(),
$apiRequest->getPath(),
['Content-Type' => 'application/json'],
json_encode($this->buildBody($apiRequest))
);
}

throw new \Exception("Can't build request");
}

Expand Down

0 comments on commit 99f11c7

Please sign in to comment.