attributes-trait.php
4 years ago
condition-helper.php
4 years ago
curl-helper.php
4 years ago
factory.php
4 years ago
gallery.php
4 years ago
get-icon-trait.php
4 years ago
get-template-trait.php
4 years ago
instance-trait.php
4 years ago
listing-filter-manager.php
4 years ago
listing-filter.php
4 years ago
messages-helper-trait.php
4 years ago
tools.php
4 years ago
curl-helper.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes; |
| 5 | |
| 6 | |
| 7 | class Curl_Helper { |
| 8 | |
| 9 | public $curl; |
| 10 | public $url; |
| 11 | public $fields = array(); |
| 12 | public $result; |
| 13 | public $options = array(); |
| 14 | public $headers = array(); |
| 15 | |
| 16 | |
| 17 | public function __construct( $url ) { |
| 18 | $this->curl = curl_init(); |
| 19 | $this->url = $url; |
| 20 | } |
| 21 | |
| 22 | public function add_header( $name, $value ) { |
| 23 | $this->headers[] = "$name:$value"; |
| 24 | } |
| 25 | |
| 26 | public function set_headers( $headers ) { |
| 27 | foreach ( $headers as $name => $value ) { |
| 28 | $this->add_header( $name, $value ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public function set_post_fields( $fields ) { |
| 33 | if ( $fields ) { |
| 34 | $this->options[ CURLOPT_POSTFIELDS ] = $fields; |
| 35 | } |
| 36 | |
| 37 | return $this; |
| 38 | } |
| 39 | |
| 40 | public function set_auth( $auth ) { |
| 41 | $this->options[ CURLOPT_USERNAME ] = $auth; |
| 42 | |
| 43 | return $this; |
| 44 | } |
| 45 | |
| 46 | private function set_options() { |
| 47 | $this->options += array( |
| 48 | CURLOPT_URL => $this->url, |
| 49 | CURLOPT_RETURNTRANSFER => true, |
| 50 | CURLOPT_TIMEOUT => 10, |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | public function set_post( $is_post = true ) { |
| 55 | if ( $is_post ) { |
| 56 | $this->options[ CURLOPT_POST ] = $is_post; |
| 57 | } |
| 58 | |
| 59 | return $this; |
| 60 | } |
| 61 | |
| 62 | public function execute() { |
| 63 | $this->set_options(); |
| 64 | |
| 65 | curl_setopt_array( $this->curl, $this->options ); |
| 66 | curl_setopt( $this->curl, CURLOPT_HTTPHEADER, $this->headers ); |
| 67 | |
| 68 | $this->result = curl_exec( $this->curl ); |
| 69 | |
| 70 | return $this->result; |
| 71 | } |
| 72 | |
| 73 | } |
| 74 |