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 11# Change Log
22
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.
39
410## 1.0.0 - 2016-01-26
511
Original file line number Diff line number Diff line change 4343 },
4444 "extra" : {
4545 "branch-alias" : {
46- "dev-master" : " 1.0 -dev"
46+ "dev-master" : " 1.1 -dev"
4747 }
4848 },
49- "prefer-stable" : true ,
50- "minimum-stability" : " beta"
49+ "prefer-stable" : true
5150}
Original file line number Diff line number Diff line change @@ -28,14 +28,24 @@ class Client implements HttpClient, HttpAsyncClient
2828 public function __construct (ClientInterface $ client = null )
2929 {
3030 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 ();
3432 }
3533
3634 $ this ->client = $ client ;
3735 }
3836
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+
3949 /**
4050 * {@inheritdoc}
4151 */
@@ -55,4 +65,20 @@ public function sendAsyncRequest(RequestInterface $request)
5565
5666 return new Promise ($ promise , $ request );
5767 }
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+ }
5884}
You can’t perform that action at this time.
0 commit comments