API_JSON_Request.php
| 1 | <?php |
| 2 | |
| 3 | namespace WooCommerce\Square\Framework\Api; |
| 4 | |
| 5 | defined( 'ABSPATH' ) or exit; |
| 6 | |
| 7 | /** |
| 8 | * Base JSON API request class. |
| 9 | * |
| 10 | * @since 3.0.0 |
| 11 | */ |
| 12 | abstract class API_JSON_Request implements API_Request { |
| 13 | |
| 14 | |
| 15 | /** @var string The request method, one of HEAD, GET, PUT, PATCH, POST, DELETE */ |
| 16 | protected $method; |
| 17 | |
| 18 | /** @var string The request path */ |
| 19 | protected $path; |
| 20 | |
| 21 | /** @var array The request parameters, if any */ |
| 22 | protected $params = array(); |
| 23 | |
| 24 | /** @var array the request data */ |
| 25 | protected $data = array(); |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Get the request method. |
| 30 | * |
| 31 | * @since 3.0.0 |
| 32 | * @see API_Request::get_method() |
| 33 | * @return string |
| 34 | */ |
| 35 | public function get_method() { |
| 36 | return $this->method; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Get the request path. |
| 42 | * |
| 43 | * @since 3.0.0 |
| 44 | * @see API_Request::get_path() |
| 45 | * @return string |
| 46 | */ |
| 47 | public function get_path() { |
| 48 | return $this->path; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /** |
| 53 | * Get the request parameters. |
| 54 | * |
| 55 | * @since 3.0.0 |
| 56 | * @see API_Request::get_params() |
| 57 | * @return array |
| 58 | */ |
| 59 | public function get_params() { |
| 60 | return $this->params; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * Get the request data. |
| 66 | * |
| 67 | * @since 3.0.0 |
| 68 | * @return array |
| 69 | */ |
| 70 | public function get_data() { |
| 71 | return $this->data; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /** API Helper Methods ******************************************************/ |
| 76 | |
| 77 | |
| 78 | /** |
| 79 | * Get the string representation of this request. |
| 80 | * |
| 81 | * @since 3.0.0 |
| 82 | * @see API_Request::to_string() |
| 83 | * @return string |
| 84 | */ |
| 85 | public function to_string() { |
| 86 | |
| 87 | $data = $this->get_data(); |
| 88 | |
| 89 | return ! empty( $data ) ? wp_json_encode( $data ) : ''; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /** |
| 94 | * Get the string representation of this request with any and all sensitive elements masked |
| 95 | * or removed. |
| 96 | * |
| 97 | * @since 3.0.0 |
| 98 | * @see API_Request::to_string_safe() |
| 99 | * @return string |
| 100 | */ |
| 101 | public function to_string_safe() { |
| 102 | |
| 103 | return $this->to_string(); |
| 104 | } |
| 105 | } |
| 106 |