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 | * Constructor |
||
69 | * |
||
70 | * Check dependancy |
||
71 | * Initialise curl connection |
||
72 | * Check parsers |
||
73 | */ |
||
74 | public function __construct(&$parserOutput = null, &$parserInput = null) |
||
89 | |||
90 | /** |
||
91 | * Check if all php librairie required is active |
||
92 | * |
||
93 | * @throws Exception |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | protected function checkLib() |
||
104 | |||
105 | /** |
||
106 | * Check if datas parser is a object and implement parser interface |
||
107 | * |
||
108 | * @param mixed &$parser Parser to use |
||
109 | * |
||
110 | * @throws Exception If error is find on parser definition |
||
111 | */ |
||
112 | protected function checkParser(&$parser) |
||
126 | |||
127 | /** |
||
128 | * Set url to call |
||
129 | * |
||
130 | * @param string $url : Url to call |
||
131 | * |
||
132 | * @return \bultonFr\CallCurl : Current class instance |
||
133 | * |
||
134 | * @throws Exception : If parameter is not a string |
||
135 | */ |
||
136 | public function setUrl($url) |
||
146 | |||
147 | /** |
||
148 | * Getter to url to call |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | public function getUrl() |
||
156 | |||
157 | /** |
||
158 | * Set datas to send with curl |
||
159 | * |
||
160 | * @param mixed $datas |
||
161 | * |
||
162 | * @return \bultonFr\CallCurl : Current class instance |
||
163 | */ |
||
164 | public function setDatas($datas) |
||
170 | |||
171 | /** |
||
172 | * Getter to datas send with curl |
||
173 | * |
||
174 | * @return mixed |
||
175 | */ |
||
176 | public function getDatas() |
||
180 | |||
181 | /** |
||
182 | * Set HTTP method to use to call |
||
183 | * ex: GET, POST, PUT, DELETE etc |
||
184 | * |
||
185 | * @param string $method : The HTTP method to use |
||
186 | * |
||
187 | * @return \bultonFr\CallCurl : Current class instance |
||
188 | * |
||
189 | * @throws Exception : If parameter is not a string |
||
190 | */ |
||
191 | public function setHttpMethod($method) |
||
201 | |||
202 | /** |
||
203 | * Set debug mode. |
||
204 | * Curl call return more informations to help |
||
205 | * |
||
206 | * @param boolean $debug : Debug mode status |
||
207 | * |
||
208 | * @return \bultonFr\CallCurl : Current class instance |
||
209 | * |
||
210 | * @throws Exception : If parameter is not a boolean |
||
211 | */ |
||
212 | public function setDebug($debug) |
||
222 | |||
223 | /** |
||
224 | * Set if curl check SSL certificate |
||
225 | * |
||
226 | * @param type $checkSSL : check SSL status |
||
227 | * |
||
228 | * @return \bultonFr\CallCurl : Current class instance |
||
229 | * |
||
230 | * @throws Exception : If parameter is not a boolean |
||
231 | */ |
||
232 | public function setCheckSSL($checkSSL) |
||
242 | |||
243 | /** |
||
244 | * Get curl returned datas after parser formating |
||
245 | * |
||
246 | * @return mixed |
||
247 | */ |
||
248 | public function getCurlReturnDatas() |
||
252 | |||
253 | /** |
||
254 | * Get curl call information |
||
255 | * |
||
256 | * @see http://php.net/manual/fr/function.curl-getinfo.php |
||
257 | * |
||
258 | * @return boolean|array : false if error. else, array to information |
||
259 | */ |
||
260 | public function getCurlCallInfos() |
||
264 | |||
265 | /** |
||
266 | * Run curl call stack |
||
267 | * * Formating datas before call |
||
268 | * * Generating curl options array |
||
269 | * * Run call |
||
270 | * * Formating datas returned by curl |
||
271 | * |
||
272 | * @return mixed Datas returned by curl |
||
273 | */ |
||
274 | public function runCall() |
||
286 | |||
287 | /** |
||
288 | * Define curl options array |
||
289 | * |
||
290 | * @return array : Options array to curl call |
||
291 | */ |
||
292 | protected function curlSetOptions() |
||
314 | |||
315 | protected function curlOptionsAddDatas(&$options) |
||
349 | |||
350 | /** |
||
351 | * Run curl call and get informations about call |
||
352 | * |
||
353 | * @return void |
||
354 | */ |
||
355 | protected function getFromCurl() |
||
362 | } |
||
363 |