I would like to get you opinion on this class, which is used to send HTTP requests (at that moment only POST method).
It is working ok, but I would like to get response on maintainability, reusability, security, code formatting, etc...
Class HttpRequest{
private $POST = 'POST';
private $PUT = 'PUT';
private $GET = 'GET';
private $DELETE = 'DELETE';
private $PATCH = 'PATCH';
private $body;
private $options;
private $handle;
private $httpCode;
private $response;
public function __construct(){}
/**
* send post request
* @param url
* @param header
* @param options
* @param body
* @return json object
*/
public function post($url, $header, $options, $body){
if(!$this->handle || get_resource_type($this->handle) == "Unknown"){
$this->handle = curl_init();
}
curl_setopt($this->handle, CURLOPT_URL, $url);
curl_setopt($this->handle, CURLOPT_HTTPHEADER, $header);
curl_setopt_array($this->handle, $options);
// curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, true);
// curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $this->POST);
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $body);
$this->response = curl_exec($this->handle);
$this->httpCode = curl_getinfo($this->handle, CURLINFO_HTTP_CODE);
curl_close($this->handle);
return $this->response;
}
public function getResponse(){
return $this->response;
}
public function getHttpCode(){
return $this->httpCode;
}
/**
* send get request
* @param url
* @param header
* @param options
*/
public function get($url,$header=array(), $options=array()){
/**
* @todo
* implemets this method
*/
}
/**
* send patch request
*/
public function patch(){
/**
* @todo
* implemets this method
*/
}
/**
* send delete request
*/
public function delete(){
/**
* @todo
* implemets this method
*/
}
/**
* send put request
*/
public function put(){
/**
* @todo
* implemets this method
*/
}
}
?>