77
88use Guzzle \Http \Client as Guzzle3Client ;
99use Guzzle \Http \ClientInterface as Guzzle3ClientInterface ;
10- use GuzzleHttp \Client as Guzzle4And5Client ;
11- use GuzzleHttp \ClientInterface as Guzzle4And5ClientInterface ;
10+ use GuzzleHttp \Client as Guzzle456Client ;
11+ use GuzzleHttp \ClientInterface as Guzzle456ClientInterface ;
1212use ZendDiagnostics \Result \Failure ;
1313use ZendDiagnostics \Result \Success ;
1414
@@ -48,7 +48,7 @@ public function __construct($url, array $headers = array(), array $options = arr
4848 $ guzzle = $ this ->createGuzzleClient ();
4949 }
5050
51- if ((!$ guzzle instanceof Guzzle3ClientInterface) && (!$ guzzle instanceof Guzzle4And5ClientInterface )) {
51+ if ((!$ guzzle instanceof Guzzle3ClientInterface) && (!$ guzzle instanceof Guzzle456ClientInterface )) {
5252 throw new \InvalidArgumentException ('Parameter "guzzle" must be an instance of "\Guzzle\Http\ClientInterface" or "\GuzzleHttp\ClientInterface" ' );
5353 }
5454
@@ -64,7 +64,7 @@ public function check()
6464 return $ this ->guzzle3Check ();
6565 }
6666
67- return $ this ->guzzle4And5Check ();
67+ return $ this ->guzzle456Check ();
6868 }
6969
7070 /**
@@ -94,18 +94,30 @@ private function guzzle3Check()
9494 /**
9595 * @return Failure|Success
9696 */
97- private function guzzle4And5Check ()
97+ private function guzzle456Check ()
9898 {
99- $ request = $ this ->guzzle ->createRequest (
100- $ this ->method ,
101- $ this ->url ,
102- array_merge (
103- array ('headers ' => $ this ->headers , 'body ' => $ this ->body , 'exceptions ' => false ),
104- $ this ->options
105- )
106- );
107-
108- $ response = $ this ->guzzle ->send ($ request );
99+ if (method_exists ($ this ->guzzle , 'request ' )) {
100+ // guzzle 6
101+ $ response = $ this ->guzzle ->request (
102+ $ this ->method ,
103+ $ this ->url ,
104+ array_merge (
105+ array ('headers ' => $ this ->headers , 'body ' => $ this ->body , 'exceptions ' => false ),
106+ $ this ->options
107+ )
108+ );
109+ } else {
110+ // guzzle 4 and 5
111+ $ request = $ this ->guzzle ->createRequest (
112+ $ this ->method ,
113+ $ this ->url ,
114+ array_merge (
115+ array ('headers ' => $ this ->headers , 'body ' => $ this ->body , 'exceptions ' => false ),
116+ $ this ->options
117+ )
118+ );
119+ $ response = $ this ->guzzle ->send ($ request );
120+ }
109121
110122 if ($ this ->statusCode !== $ statusCode = (int ) $ response ->getStatusCode ()) {
111123 return $ this ->createStatusCodeFailure ($ statusCode );
@@ -144,7 +156,7 @@ private function createContentFailure()
144156 private function createGuzzleClient ()
145157 {
146158 if (class_exists ('GuzzleHttp\Client ' )) {
147- return new Guzzle4And5Client ();
159+ return new Guzzle456Client ();
148160 }
149161
150162 if (!class_exists ('Guzzle\Http\Client ' )) {
0 commit comments