Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2. class Curl {
  3. private $_ch;
  4. protected $opts;
  5.  
  6. private function __construct($config)
  7. {
  8. $this->_ch = curl_init();
  9. }
  10.  
  11. public static function init()
  12. {
  13. if(!function_exists('curl_version')
  14. || !in_array('curl', get_loaded_extensions())
  15. || !extension_loaded('curl')
  16. ) :
  17. throw new Exception("Please install / enable Curl on your server",400);
  18. endif;
  19. return new Curl(func_get_args());
  20. }
  21.  
  22. public function send($url, $method = "GET", $data = array())
  23. {
  24. $opts["url"] = $this->url;
  25. $opts["method"] = $this->method;
  26. $opts["data"] = $this->data;
  27. $this->opts = array_replace_recursive($this->opts, $opts);
  28. curl_setopt_array($this->_ch, $this->opts);
  29. $resp = curl_exec($this->_ch);
  30. if($resp === FALSE) :
  31. if(ini_get('display_errors')) :
  32. throw new Exception('Curl Error: ' . curl_error($this->_ch),417);
  33. else :
  34. error_log('Curl Error: ' . curl_error($this->_ch));
  35. endif;
  36. endif;
  37. // $curl->getResponseHeader();
  38. // $curl->getResponseBody();
  39. return $resp;
  40. }
  41.  
  42. private function __destruct()
  43. {
  44. curl_close($this->_ch);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement