18
18
use Http \Client \Exception \BatchException ;
19
19
use Http \Client \Exception \HttpException ;
20
20
use Http \Client \Exception \NetworkException ;
21
+ use Http \Client \Exception ;
21
22
use Http \Client \HttpClient ;
22
23
use Http \Client \Utils \BatchResult ;
23
24
use Psr \Http \Message \RequestInterface ;
@@ -33,19 +34,12 @@ class Guzzle6HttpAdapter implements HttpClient
33
34
*/
34
35
private $ client ;
35
36
36
- /**
37
- * @var array Options to pass when sending one or multiple requests with guzzle
38
- */
39
- private $ options ;
40
-
41
37
/**
42
38
* @param ClientInterface|null $client Guzzle client
43
- * @param array $options Options to pass when sending one or multiple requests with guzzle
44
39
*/
45
- public function __construct (ClientInterface $ client = null , array $ options = [] )
40
+ public function __construct (ClientInterface $ client = null )
46
41
{
47
- $ this ->client = $ client ?: new Client ();
48
- $ this ->options = $ this ->buildOptions ($ options );
42
+ $ this ->client = $ client ?: new Client ();
49
43
}
50
44
51
45
/**
@@ -54,7 +48,7 @@ public function __construct(ClientInterface $client = null, array $options = [])
54
48
public function sendRequest (RequestInterface $ request )
55
49
{
56
50
try {
57
- return $ this ->client ->send ($ request, $ this -> options );
51
+ return $ this ->client ->send ($ request );
58
52
} catch (RequestException $ e ) {
59
53
throw $ this ->createException ($ e );
60
54
}
@@ -65,7 +59,7 @@ public function sendRequest(RequestInterface $request)
65
59
*/
66
60
public function sendRequests (array $ requests )
67
61
{
68
- $ poolResult = Pool::batch ($ this ->client , $ requests, [ ' options ' => $ this -> options ] );
62
+ $ poolResult = Pool::batch ($ this ->client , $ requests );
69
63
$ batchResult = new BatchResult ();
70
64
71
65
foreach ($ poolResult as $ index => $ result ) {
@@ -90,7 +84,7 @@ public function sendRequests(array $requests)
90
84
*
91
85
* @param RequestException $exception
92
86
*
93
- * @return HttpException|NetworkException Return an HttpException if response is available, NetworkException otherwise
87
+ * @return Exception
94
88
*/
95
89
private function createException (RequestException $ exception )
96
90
{
@@ -100,26 +94,4 @@ private function createException(RequestException $exception)
100
94
101
95
return new NetworkException ($ exception ->getMessage (), $ exception ->getRequest (), $ exception );
102
96
}
103
-
104
- /**
105
- * Builds options for Guzzle
106
- *
107
- * @param array $options
108
- *
109
- * @return array
110
- */
111
- private function buildOptions (array $ options )
112
- {
113
- $ guzzleOptions = [
114
- 'http_errors ' => false ,
115
- 'allow_redirects ' => false ,
116
- ];
117
-
118
- if (isset ($ options ['timeout ' ])) {
119
- $ guzzleOptions ['connect_timeout ' ] = $ options ['timeout ' ];
120
- $ guzzleOptions ['timeout ' ] = $ options ['timeout ' ];
121
- }
122
-
123
- return $ guzzleOptions ;
124
- }
125
97
}
0 commit comments