1 | <?php |
||
15 | class CallCurl |
||
16 | { |
||
17 | /** |
||
18 | * @var resource $curl Curl resource |
||
19 | */ |
||
20 | protected $curl = null; |
||
21 | |||
22 | /** |
||
23 | * @var Object $parserInput PHP Class used for parse data before call |
||
24 | */ |
||
25 | protected $parserOutput = null; |
||
26 | |||
27 | /** |
||
28 | * @var Object $parserOutput PHP Class used for parse data after call |
||
29 | */ |
||
30 | protected $parserInput = null; |
||
31 | |||
32 | /** |
||
33 | * @var string $url The url to call with curl |
||
34 | */ |
||
35 | protected $url = ''; |
||
36 | |||
37 | /** |
||
38 | * @var mixed $datas Datas to send with curl |
||
39 | */ |
||
40 | protected $datas = ''; |
||
41 | |||
42 | /** |
||
43 | * @var string $httpMethod The HTTP method to use for curl call |
||
44 | */ |
||
45 | protected $httpMethod = 'GET'; |
||
46 | |||
47 | /** |
||
48 | * @var boolean $debug Ask to curl more datas to return for help debug |
||
49 | */ |
||
50 | protected $debug = false; |
||
51 | |||
52 | /** |
||
53 | * @var boolean $checkSSL If curl doing check SSL certificate |
||
54 | */ |
||
55 | protected $checkSSL = true; |
||
56 | |||
57 | /** |
||
58 | * @var mixed $returnDatas : Datas return by curl call |
||
59 | */ |
||
60 | protected $returnDatas; |
||
61 | |||
62 | /** |
||
63 | * @var boolean|array $curlCallInfos : Informations returned by curl |
||
64 | */ |
||
65 | protected $curlCallInfos; |
||
66 | |||
67 | /** |
||
68 | * @var array $httpHeaders : Custom headers to send with http request |
||
69 | */ |
||
70 | protected $httpHeaders = []; |
||
71 | |||
72 | /** |
||
73 | * Constructor |
||
74 | * |
||
75 | * Check dependancy |
||
76 | * Initialise curl connection |
||
77 | * Check parsers |
||
78 | */ |
||
79 | public function __construct(&$parserOutput = null, &$parserInput = null) |
||
94 | |||
95 | /** |
||
96 | * Check if all php librairie required is active |
||
97 | * |
||
98 | * @throws Exception |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | protected function checkLib() |
||
109 | |||
110 | /** |
||
111 | * Check if datas parser is a object and implement parser interface |
||
112 | * |
||
113 | * @param mixed &$parser Parser to use |
||
114 | * |
||
115 | * @throws Exception If error is find on parser definition |
||
116 | */ |
||
117 | protected function checkParser(&$parser) |
||
131 | |||
132 | /** |
||
133 | * Set url to call |
||
134 | * |
||
135 | * @param string $url : Url to call |
||
136 | * |
||
137 | * @return \bultonFr\CallCurl : Current class instance |
||
138 | * |
||
139 | * @throws Exception : If parameter is not a string |
||
140 | */ |
||
141 | public function setUrl($url) |
||
151 | |||
152 | /** |
||
153 | * Getter to url to call |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | public function getUrl() |
||
161 | |||
162 | /** |
||
163 | * Set datas to send with curl |
||
164 | * |
||
165 | * @param mixed $datas |
||
166 | * |
||
167 | * @return \bultonFr\CallCurl : Current class instance |
||
168 | */ |
||
169 | public function setDatas($datas) |
||
175 | |||
176 | /** |
||
177 | * Getter to datas send with curl |
||
178 | * |
||
179 | * @return mixed |
||
180 | */ |
||
181 | public function getDatas() |
||
185 | |||
186 | /** |
||
187 | * Set HTTP method to use to call |
||
188 | * ex: GET, POST, PUT, DELETE etc |
||
189 | * |
||
190 | * @param string $method : The HTTP method to use |
||
191 | * |
||
192 | * @return \bultonFr\CallCurl : Current class instance |
||
193 | * |
||
194 | * @throws Exception : If parameter is not a string |
||
195 | */ |
||
196 | public function setHttpMethod($method) |
||
206 | |||
207 | /** |
||
208 | * Set debug mode. |
||
209 | * Curl call return more informations to help |
||
210 | * |
||
211 | * @param boolean $debug : Debug mode status |
||
212 | * |
||
213 | * @return \bultonFr\CallCurl : Current class instance |
||
214 | * |
||
215 | * @throws Exception : If parameter is not a boolean |
||
216 | */ |
||
217 | public function setDebug($debug) |
||
227 | |||
228 | /** |
||
229 | * Set if curl check SSL certificate |
||
230 | * |
||
231 | * @param type $checkSSL : check SSL status |
||
232 | * |
||
233 | * @return \bultonFr\CallCurl : Current class instance |
||
234 | * |
||
235 | * @throws Exception : If parameter is not a boolean |
||
236 | */ |
||
237 | public function setCheckSSL($checkSSL) |
||
247 | |||
248 | /** |
||
249 | * Get curl returned datas after parser formating |
||
250 | * |
||
251 | * @return mixed |
||
252 | */ |
||
253 | public function getCurlReturnDatas() |
||
257 | |||
258 | /** |
||
259 | * Get curl call information |
||
260 | * |
||
261 | * @see http://php.net/manual/fr/function.curl-getinfo.php |
||
262 | * |
||
263 | * @return boolean|array : false if error. else, array to information |
||
264 | */ |
||
265 | public function getCurlCallInfos() |
||
269 | |||
270 | /** |
||
271 | * Http header to add on the request |
||
272 | * |
||
273 | * @param array $header |
||
274 | */ |
||
275 | public function addHttpHeader($header) |
||
279 | |||
280 | /** |
||
281 | * Run curl call stack |
||
282 | * * Formating datas before call |
||
283 | * * Generating curl options array |
||
284 | * * Run call |
||
285 | * * Formating datas returned by curl |
||
286 | * |
||
287 | * @return mixed Datas returned by curl |
||
288 | */ |
||
289 | public function runCall() |
||
301 | |||
302 | /** |
||
303 | * Define curl options array |
||
304 | * |
||
305 | * @return array : Options array to curl call |
||
306 | */ |
||
307 | protected function curlSetOptions() |
||
330 | |||
331 | protected function curlOptionsAddDatas(&$options) |
||
365 | |||
366 | protected function curlOptionsAddHttpHeaders(&$options) |
||
386 | |||
387 | /** |
||
388 | * Run curl call and get informations about call |
||
389 | * |
||
390 | * @return void |
||
391 | */ |
||
392 | protected function getFromCurl() |
||
399 | } |
||
400 |