Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #63 from easybiblabs/t/guzzle-6-compat
Browse files Browse the repository at this point in the history
guzzle 6 compatibility
  • Loading branch information
lsmith77 committed Oct 1, 2015
2 parents 90c6197 + 51dc34e commit 6ffffbe
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/ZendDiagnostics/Check/GuzzleHttpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use Guzzle\Http\Client as Guzzle3Client;
use Guzzle\Http\ClientInterface as Guzzle3ClientInterface;
use GuzzleHttp\Client as Guzzle4And5Client;
use GuzzleHttp\ClientInterface as Guzzle4And5ClientInterface;
use GuzzleHttp\Client as Guzzle456Client;
use GuzzleHttp\ClientInterface as Guzzle456ClientInterface;
use ZendDiagnostics\Result\Failure;
use ZendDiagnostics\Result\Success;

Expand Down Expand Up @@ -48,7 +48,7 @@ public function __construct($url, array $headers = array(), array $options = arr
$guzzle = $this->createGuzzleClient();
}

if ((!$guzzle instanceof Guzzle3ClientInterface) && (!$guzzle instanceof Guzzle4And5ClientInterface)) {
if ((!$guzzle instanceof Guzzle3ClientInterface) && (!$guzzle instanceof Guzzle456ClientInterface)) {
throw new \InvalidArgumentException('Parameter "guzzle" must be an instance of "\Guzzle\Http\ClientInterface" or "\GuzzleHttp\ClientInterface"');
}

Expand All @@ -64,7 +64,7 @@ public function check()
return $this->guzzle3Check();
}

return $this->guzzle4And5Check();
return $this->guzzle456Check();
}

/**
Expand Down Expand Up @@ -94,18 +94,30 @@ private function guzzle3Check()
/**
* @return Failure|Success
*/
private function guzzle4And5Check()
private function guzzle456Check()
{
$request = $this->guzzle->createRequest(
$this->method,
$this->url,
array_merge(
array('headers' => $this->headers, 'body' => $this->body, 'exceptions' => false),
$this->options
)
);

$response = $this->guzzle->send($request);
if (method_exists($this->guzzle, 'request')) {
// guzzle 6
$response = $this->guzzle->request(
$this->method,
$this->url,
array_merge(
array('headers' => $this->headers, 'body' => $this->body, 'exceptions' => false),
$this->options
)
);
} else {
// guzzle 4 and 5
$request = $this->guzzle->createRequest(
$this->method,
$this->url,
array_merge(
array('headers' => $this->headers, 'body' => $this->body, 'exceptions' => false),
$this->options
)
);
$response = $this->guzzle->send($request);
}

if ($this->statusCode !== $statusCode = (int) $response->getStatusCode()) {
return $this->createStatusCodeFailure($statusCode);
Expand Down Expand Up @@ -144,7 +156,7 @@ private function createContentFailure()
private function createGuzzleClient()
{
if (class_exists('GuzzleHttp\Client')) {
return new Guzzle4And5Client();
return new Guzzle456Client();
}

if (!class_exists('Guzzle\Http\Client')) {
Expand Down

0 comments on commit 6ffffbe

Please sign in to comment.