This repository was archived by the owner on Jan 6, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +37
-6
lines changed Expand file tree Collapse file tree 3 files changed +37
-6
lines changed Original file line number Diff line number Diff line change 1
1
# Change Log
2
2
3
+ ## 1.1.0 (unreleased)
4
+
5
+ ### Added
6
+
7
+ - Factory method Client::createWithConfig to create an adapter with custom
8
+ configuration for the underlying guzzle client.
3
9
4
10
## 1.0.0 - 2016-01-26
5
11
Original file line number Diff line number Diff line change 43
43
},
44
44
"extra" : {
45
45
"branch-alias" : {
46
- "dev-master" : " 1.0 -dev"
46
+ "dev-master" : " 1.1 -dev"
47
47
}
48
48
},
49
- "prefer-stable" : true ,
50
- "minimum-stability" : " beta"
49
+ "prefer-stable" : true
51
50
}
Original file line number Diff line number Diff line change @@ -28,14 +28,24 @@ class Client implements HttpClient, HttpAsyncClient
28
28
public function __construct (ClientInterface $ client = null )
29
29
{
30
30
if (!$ client ) {
31
- $ handlerStack = new HandlerStack (\GuzzleHttp \choose_handler ());
32
- $ handlerStack ->push (Middleware::prepareBody (), 'prepare_body ' );
33
- $ client = new GuzzleClient (['handler ' => $ handlerStack ]);
31
+ $ client = static ::buildClient ();
34
32
}
35
33
36
34
$ this ->client = $ client ;
37
35
}
38
36
37
+ /**
38
+ * Factory method to create the guzzle 6 adapter with custom configuration for guzzle.
39
+ *
40
+ * @param array $config Configuration to create guzzle with.
41
+ *
42
+ * @return Client
43
+ */
44
+ public static function createWithConfig (array $ config )
45
+ {
46
+ return new self (static ::buildClient ($ config ));
47
+ }
48
+
39
49
/**
40
50
* {@inheritdoc}
41
51
*/
@@ -55,4 +65,20 @@ public function sendAsyncRequest(RequestInterface $request)
55
65
56
66
return new Promise ($ promise , $ request );
57
67
}
68
+
69
+ /**
70
+ * Build the guzzle client instance.
71
+ *
72
+ * @param array $config Additional configuration
73
+ *
74
+ * @return GuzzleClient
75
+ */
76
+ private static function buildClient (array $ config )
77
+ {
78
+ $ handlerStack = new HandlerStack (\GuzzleHttp \choose_handler ());
79
+ $ handlerStack ->push (Middleware::prepareBody (), 'prepare_body ' );
80
+ $ config = array_merge (['handler ' => $ handlerStack ], $ config );
81
+
82
+ return new GuzzleClient ($ config );
83
+ }
58
84
}
You can’t perform that action at this time.
0 commit comments