@@ -29,50 +29,54 @@ class Client
2929 /** @var array */
3030 protected $ path ;
3131 /** @var array */
32+ protected $ curlOptions ;
33+ /** @var array */
3234 private $ methods ;
3335
3436 /**
3537 * Initialize the client
3638 *
37- * @param string $host the base url (e.g. https://api.sendgrid.com)
38- * @param array $headers global request headers
39- * @param string $version api version (configurable)
40- * @param array $path holds the segments of the url path
39+ * @param string $host the base url (e.g. https://api.sendgrid.com)
40+ * @param array $headers global request headers
41+ * @param string $version api version (configurable)
42+ * @param array $path holds the segments of the url path
43+ * @param array $curlOptions extra options to set during curl initialization
4144 */
42- public function __construct ($ host , $ headers = null , $ version = null , $ path = null )
45+ public function __construct ($ host , $ headers = null , $ version = null , $ path = null , $ curlOptions = null )
4346 {
4447 $ this ->host = $ host ;
4548 $ this ->headers = $ headers ?: [];
4649 $ this ->version = $ version ;
4750 $ this ->path = $ path ?: [];
51+ $ this ->curlOptions = $ curlOptions ?: [];
4852 // These are the supported HTTP verbs
4953 $ this ->methods = ['delete ' , 'get ' , 'patch ' , 'post ' , 'put ' ];
5054 }
51-
55+
5256 /**
5357 * @return string
5458 */
5559 public function getHost ()
5660 {
5761 return $ this ->host ;
5862 }
59-
63+
6064 /**
6165 * @return array
6266 */
6367 public function getHeaders ()
6468 {
6569 return $ this ->headers ;
6670 }
67-
71+
6872 /**
6973 * @return string|null
7074 */
7175 public function getVersion ()
7276 {
7377 return $ this ->version ;
7478 }
75-
79+
7680 /**
7781 * @return array
7882 */
@@ -81,6 +85,14 @@ public function getPath()
8185 return $ this ->path ;
8286 }
8387
88+ /**
89+ * @return array
90+ */
91+ public function getCurlOptions ()
92+ {
93+ return $ this ->curlOptions ;
94+ }
95+
8496 /**
8597 * Make a new Client object
8698 *
@@ -129,12 +141,12 @@ public function makeRequest($method, $url, $body = null, $headers = null)
129141 {
130142 $ curl = curl_init ($ url );
131143
132- curl_setopt_array ($ curl , [
144+ curl_setopt_array ($ curl , array_merge ( [
133145 CURLOPT_RETURNTRANSFER => true ,
134146 CURLOPT_HEADER => 1 ,
135147 CURLOPT_CUSTOMREQUEST => strtoupper ($ method ),
136148 CURLOPT_SSL_VERIFYPEER => false ,
137- ]);
149+ ], $ this -> curlOptions ) );
138150
139151 if (isset ($ headers )) {
140152 $ this ->headers = array_merge ($ this ->headers , $ headers );
0 commit comments