@@ -790,20 +790,32 @@ protected function populateResponse(Response $response)
790
790
*/
791
791
public function buildClient ()
792
792
{
793
- return $ this ->client = $ this ->client ?: new Client ([
794
- 'handler ' => $ this ->buildHandlerStack (),
793
+ return $ this ->client = $ this ->client ?: $ this ->createClient ($ this ->buildHandlerStack ());
794
+ }
795
+
796
+ /**
797
+ * Create new Guzzle client.
798
+ *
799
+ * @param \GuzzleHttp\HandlerStack $handlerStack
800
+ * @return \GuzzleHttp\Client
801
+ */
802
+ public function createClient ($ handlerStack )
803
+ {
804
+ return new Client ([
805
+ 'handler ' => $ handlerStack ,
795
806
'cookies ' => true ,
796
807
]);
797
808
}
798
809
799
810
/**
800
- * Build the before sending handler stack.
811
+ * add handlers to the handler stack
801
812
*
813
+ * @param \GuzzleHttp\HandlerStack $handlerStack
802
814
* @return \GuzzleHttp\HandlerStack
803
815
*/
804
- public function buildHandlerStack ( )
816
+ public function pushHandlers ( $ handlerStack )
805
817
{
806
- return tap (HandlerStack:: create () , function ($ stack ) {
818
+ return tap ($ handlerStack , function ($ stack ) {
807
819
$ stack ->push ($ this ->buildBeforeSendingHandler ());
808
820
$ stack ->push ($ this ->buildRecorderHandler ());
809
821
$ stack ->push ($ this ->buildStubHandler ());
@@ -814,6 +826,16 @@ public function buildHandlerStack()
814
826
});
815
827
}
816
828
829
+ /**
830
+ * Build the before sending handler stack.
831
+ *
832
+ * @return \GuzzleHttp\HandlerStack
833
+ */
834
+ public function buildHandlerStack ()
835
+ {
836
+ return $ this ->pushHandlers (HandlerStack::create ());
837
+ }
838
+
817
839
/**
818
840
* Build the before sending handler.
819
841
*
@@ -1022,4 +1044,17 @@ public function setClient(Client $client)
1022
1044
1023
1045
return $ this ;
1024
1046
}
1047
+
1048
+ /**
1049
+ * set the handler function
1050
+ *
1051
+ * @param callable $handler
1052
+ * @return $this
1053
+ */
1054
+ public function setHandler ($ handler )
1055
+ {
1056
+ $ this ->client = $ this ->createClient ($ this ->pushHandlers (HandlerStack::create ($ handler )));
1057
+
1058
+ return $ this ;
1059
+ }
1025
1060
}
0 commit comments