3030/**
3131 * Base REST API Request class
3232 *
33- * @since 3.1.2-1
33+ * @since 4.0.0
3434 */
3535class SV_WC_API_REST_Request implements SV_WC_API_Request {
3636
@@ -48,7 +48,7 @@ class SV_WC_API_REST_Request implements SV_WC_API_Request {
4848 /**
4949 * Construct REST request object
5050 *
51- * @since 3.1.2-1
51+ * @since 4.0.0
5252 * @param string $method the request method, one of HEAD, GET, PUT, PATCH, POST, DELETE
5353 * @param string $path optional request path
5454 * @param array $params optional associative array of request parameters
@@ -66,7 +66,7 @@ public function __construct( $method, $path = '', $params = array() ) {
6666 /**
6767 * Returns the method for this request: one of HEAD, GET, PUT, PATCH, POST, DELETE
6868 *
69- * @since 3.1.2-1
69+ * @since 4.0.0
7070 * @see SV_WC_API_Request::get_method()
7171 * @return string the request method
7272 */
@@ -78,7 +78,7 @@ public function get_method() {
7878 /**
7979 * Returns the request path
8080 *
81- * @since 3.1.2-1
81+ * @since 4.0.0
8282 * @see SV_WC_API_Request::get_path()
8383 * @return string the request path
8484 */
@@ -90,35 +90,54 @@ public function get_path() {
9090 /**
9191 * Returns the request params, if any
9292 *
93- * @since 3.1.2-1
93+ * @since 4.0.0
9494 * @return array the request params
9595 */
9696 public function get_params () {
9797 return $ this ->params ;
9898 }
9999
100100
101+ /**
102+ * Returns the request params, url encoded
103+ *
104+ * @since 4.0.0
105+ * @see SV_WC_API_REST_Request::get_params()
106+ * @return array the request params, url encoded
107+ */
108+ public function get_encoded_params () {
109+
110+ $ encoded_params = array ();
111+ foreach ( $ this ->get_params () as $ key => $ value ) {
112+ $ encoded_params [ $ key ] = urlencode ( $ value );
113+ }
114+
115+ return $ encoded_params ;
116+ }
117+
118+
101119 /** API Helper Methods ******************************************************/
102120
103121
104122 /**
105123 * Returns the string representation of this request
106124 *
107- * @since 3.1.2-1
125+ * @since 4.0.0
108126 * @see SV_WC_API_Request::to_string()
109127 * @return string request
110128 */
111129 public function to_string () {
130+
112131 // URL encode params
113- return build_query ( $ this ->get_params () );
132+ return build_query ( $ this ->get_encoded_params () );
114133 }
115134
116135
117136 /**
118137 * Returns the string representation of this request with any and all
119138 * sensitive elements masked or removed
120139 *
121- * @since 3.1.2-1
140+ * @since 4.0.0
122141 * @see SV_WC_API_Request::to_string_safe()
123142 * @return string the request, safe for logging/displaying
124143 */
0 commit comments