7
7
8
8
use Guzzle \Http \Client as Guzzle3Client ;
9
9
use 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 ;
12
12
use ZendDiagnostics \Result \Failure ;
13
13
use ZendDiagnostics \Result \Success ;
14
14
@@ -48,7 +48,7 @@ public function __construct($url, array $headers = array(), array $options = arr
48
48
$ guzzle = $ this ->createGuzzleClient ();
49
49
}
50
50
51
- if ((!$ guzzle instanceof Guzzle3ClientInterface) && (!$ guzzle instanceof Guzzle4And5ClientInterface )) {
51
+ if ((!$ guzzle instanceof Guzzle3ClientInterface) && (!$ guzzle instanceof Guzzle456ClientInterface )) {
52
52
throw new \InvalidArgumentException ('Parameter "guzzle" must be an instance of "\Guzzle\Http\ClientInterface" or "\GuzzleHttp\ClientInterface" ' );
53
53
}
54
54
@@ -64,7 +64,7 @@ public function check()
64
64
return $ this ->guzzle3Check ();
65
65
}
66
66
67
- return $ this ->guzzle4And5Check ();
67
+ return $ this ->guzzle456Check ();
68
68
}
69
69
70
70
/**
@@ -94,18 +94,30 @@ private function guzzle3Check()
94
94
/**
95
95
* @return Failure|Success
96
96
*/
97
- private function guzzle4And5Check ()
97
+ private function guzzle456Check ()
98
98
{
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
+ }
109
121
110
122
if ($ this ->statusCode !== $ statusCode = (int ) $ response ->getStatusCode ()) {
111
123
return $ this ->createStatusCodeFailure ($ statusCode );
@@ -144,7 +156,7 @@ private function createContentFailure()
144
156
private function createGuzzleClient ()
145
157
{
146
158
if (class_exists ('GuzzleHttp\Client ' )) {
147
- return new Guzzle4And5Client ();
159
+ return new Guzzle456Client ();
148
160
}
149
161
150
162
if (!class_exists ('Guzzle\Http\Client ' )) {
0 commit comments