Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Curl {
- private $_ch;
- protected $opts;
- private function __construct($config)
- {
- $this->_ch = curl_init();
- }
- public static function init()
- {
- if(!function_exists('curl_version')
- || !in_array('curl', get_loaded_extensions())
- || !extension_loaded('curl')
- ) :
- throw new Exception("Please install / enable Curl on your server",400);
- endif;
- return new Curl(func_get_args());
- }
- public function send($url, $method = "GET", $data = array())
- {
- $opts["url"] = $this->url;
- $opts["method"] = $this->method;
- $opts["data"] = $this->data;
- $this->opts = array_replace_recursive($this->opts, $opts);
- curl_setopt_array($this->_ch, $this->opts);
- $resp = curl_exec($this->_ch);
- if($resp === FALSE) :
- if(ini_get('display_errors')) :
- throw new Exception('Curl Error: ' . curl_error($this->_ch),417);
- else :
- error_log('Curl Error: ' . curl_error($this->_ch));
- endif;
- endif;
- // $curl->getResponseHeader();
- // $curl->getResponseBody();
- return $resp;
- }
- private function __destruct()
- {
- curl_close($this->_ch);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement