Files
2021-07-10 16:25:16 +02:00

88 lines
1.6 KiB
PHP

<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 27/11/2016
* Time: 16:00
*/
class CurlWrapper {
private $curl;
private $remoteURL;
private $method;
private $data;
private $result;
public function __construct()
{
}
public function getResult()
{
return $this->result;
}
public function handle( $remoteURL, $method = 'POST', $data = [] )
{
$this->initialize();
$this->setRemoteURL( $remoteURL );
$this->setMethod( $method );
$this->setData( $data );
$this->setCurlOptions();
$this->performRemoteCall();
$this->closeCurl();
// echo $this->result;
}
private function initialize()
{
$this->curl = curl_init();
}
private function setRemoteURL( $remoteURL )
{
$this->remoteURL = $remoteURL;
}
private function setMethod( $method )
{
$this->method = $method;
}
private function setData( $data )
{
$this->data = $data;
}
private function setCurlOptions()
{
curl_setopt_array( $this->curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $this->remoteURL,
CURLOPT_POST => $this->method == 'POST' ? TRUE : FALSE,
CURLOPT_POSTFIELDS => $this->data
]
);
}
private function performRemoteCall()
{
$this->result = curl_exec( $this->curl );
}
private function closeCurl()
{
curl_close( $this->curl );
}
}