@@ -29,50 +29,54 @@ class Client
29
29
/** @var array */
30
30
protected $ path ;
31
31
/** @var array */
32
+ protected $ curlOptions ;
33
+ /** @var array */
32
34
private $ methods ;
33
35
34
36
/**
35
37
* Initialize the client
36
38
*
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
41
44
*/
42
- public function __construct ($ host , $ headers = null , $ version = null , $ path = null )
45
+ public function __construct ($ host , $ headers = null , $ version = null , $ path = null , $ curlOptions = null )
43
46
{
44
47
$ this ->host = $ host ;
45
48
$ this ->headers = $ headers ?: [];
46
49
$ this ->version = $ version ;
47
50
$ this ->path = $ path ?: [];
51
+ $ this ->curlOptions = $ curlOptions ?: [];
48
52
// These are the supported HTTP verbs
49
53
$ this ->methods = ['delete ' , 'get ' , 'patch ' , 'post ' , 'put ' ];
50
54
}
51
-
55
+
52
56
/**
53
57
* @return string
54
58
*/
55
59
public function getHost ()
56
60
{
57
61
return $ this ->host ;
58
62
}
59
-
63
+
60
64
/**
61
65
* @return array
62
66
*/
63
67
public function getHeaders ()
64
68
{
65
69
return $ this ->headers ;
66
70
}
67
-
71
+
68
72
/**
69
73
* @return string|null
70
74
*/
71
75
public function getVersion ()
72
76
{
73
77
return $ this ->version ;
74
78
}
75
-
79
+
76
80
/**
77
81
* @return array
78
82
*/
@@ -81,6 +85,14 @@ public function getPath()
81
85
return $ this ->path ;
82
86
}
83
87
88
+ /**
89
+ * @return array
90
+ */
91
+ public function getCurlOptions ()
92
+ {
93
+ return $ this ->curlOptions ;
94
+ }
95
+
84
96
/**
85
97
* Make a new Client object
86
98
*
@@ -129,12 +141,12 @@ public function makeRequest($method, $url, $body = null, $headers = null)
129
141
{
130
142
$ curl = curl_init ($ url );
131
143
132
- curl_setopt_array ($ curl , [
144
+ curl_setopt_array ($ curl , array_merge ( [
133
145
CURLOPT_RETURNTRANSFER => true ,
134
146
CURLOPT_HEADER => 1 ,
135
147
CURLOPT_CUSTOMREQUEST => strtoupper ($ method ),
136
148
CURLOPT_SSL_VERIFYPEER => false ,
137
- ]);
149
+ ], $ this -> curlOptions ) );
138
150
139
151
if (isset ($ headers )) {
140
152
$ this ->headers = array_merge ($ this ->headers , $ headers );
0 commit comments