-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurlProcessor.php
38 lines (33 loc) · 975 Bytes
/
CurlProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
class CurlProcessor{
protected $curl;
protected $res;
protected $error;
function curlInit($config){
$this->curl = curl_init();
curl_setopt($this->curl,CURLOPT_URL,$config->getUrl());
curl_setopt($this->curl,CURLOPT_HTTPHEADER,$config->getHeaders());
curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($this->curl,CURLOPT_POST,1);
}
function curlBody($body){
curl_setopt($this->curl,CURLOPT_POSTFIELDS,$body);
}
function curlExecution(){
$this->res = curl_exec($this->curl);
if(curl_errno($this->curl)==0){
return json_decode($this->res)->translations[0]->text;
}
else{
$this->error=curl_error($this->curl);
}
}
function curlErrorHandling(){
if($this->error){
return curl_error($this->curl);
}
}
function closeRequest(){
curl_close($this->curl);
}
}