← All changes
|
vendor/hostinger/hostinger-wp-helper/src/Requests/Client.php
+23
-15
3.0.66
→
3.0.79
View file →
| @@ -1,62 +1,70 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Hostinger\WpHelper\Requests; |
| 4 | 4 | |
| 5 | -defined( 'ABSPATH' ) || exit; | |
| 5 | +defined('ABSPATH') || exit; | |
| 6 | 6 | |
| 7 | -class Client { | |
| 7 | +class Client | |
| 8 | +{ | |
| 8 | 9 | private string $api_url; |
| 9 | 10 | private array $default_headers; |
| 10 | 11 | |
| 11 | - public function __construct( $api_url, $default_headers = array() ) { | |
| 12 | + public function __construct($api_url, $default_headers = array()) | |
| 13 | + { | |
| 12 | 14 | $this->api_url = $api_url; |
| 13 | 15 | $this->default_headers = $default_headers; |
| 14 | 16 | } |
| 15 | 17 | |
| 16 | - public function get_api_url(): string { | |
| 18 | + public function get_api_url(): string | |
| 19 | + { | |
| 17 | 20 | return $this->api_url; |
| 18 | 21 | } |
| 19 | 22 | |
| 20 | - public function set_api_url( string $api_url ): void { | |
| 23 | + public function set_api_url(string $api_url): void | |
| 24 | + { | |
| 21 | 25 | $this->api_url = $api_url; |
| 22 | 26 | } |
| 23 | 27 | |
| 24 | - public function get_default_headers(): array { | |
| 28 | + public function get_default_headers(): array | |
| 29 | + { | |
| 25 | 30 | return $this->default_headers; |
| 26 | 31 | } |
| 27 | 32 | |
| 28 | - public function set_default_headers( array $default_headers ): void { | |
| 33 | + public function set_default_headers(array $default_headers): void | |
| 34 | + { | |
| 29 | 35 | $this->default_headers = $default_headers; |
| 30 | 36 | } |
| 31 | 37 | |
| 32 | - public function get( $endpoint, $params = array(), $headers = array(), $timeout = 120 ) { | |
| 38 | + public function get($endpoint, $params = array(), $headers = array(), $timeout = 120) | |
| 39 | + { | |
| 33 | 40 | $url = $this->api_url . $endpoint; |
| 34 | 41 | $request_args = array( |
| 35 | 42 | 'method' => 'GET', |
| 36 | - 'headers' => array_merge( $this->default_headers, $headers ), | |
| 43 | + 'headers' => array_merge($this->default_headers, $headers), | |
| 37 | 44 | 'timeout' => $timeout, |
| 38 | 45 | ); |
| 39 | 46 | |
| 40 | - if ( ! empty( $params ) ) { | |
| 41 | - $url = add_query_arg( $params, $url ); | |
| 47 | + if (! empty($params)) { | |
| 48 | + $url = add_query_arg($params, $url); | |
| 42 | 49 | } |
| 43 | 50 | |
| 44 | - $response = wp_remote_get( $url, $request_args ); | |
| 51 | + $response = wp_remote_get($url, $request_args); | |
| 45 | 52 | |
| 46 | 53 | return $response; |
| 47 | 54 | } |
| 48 | 55 | |
| 49 | - public function post( $endpoint, $params = array(), $headers = array(), $timeout = 120 ) { | |
| 56 | + public function post($endpoint, $params = array(), $headers = array(), $timeout = 120) | |
| 57 | + { | |
| 50 | 58 | $url = $this->api_url . $endpoint; |
| 51 | 59 | $request_args = array( |
| 52 | 60 | 'method' => 'POST', |
| 53 | 61 | 'timeout' => $timeout, |
| 54 | - 'headers' => array_merge( $this->default_headers, $headers ), | |
| 62 | + 'headers' => array_merge($this->default_headers, $headers), | |
| 55 | 63 | 'body' => $params, |
| 56 | 64 | ); |
| 57 | 65 | |
| 58 | - $response = wp_remote_post( $url, $request_args ); | |
| 66 | + $response = wp_remote_post($url, $request_args); | |
| 59 | 67 | |
| 60 | 68 | return $response; |
| 61 | 69 | } |
| 62 | 70 | } |