PluginProbe
Parse.ly / 3.20.1
Parse.ly v3.20.1
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / rest-api / class-base-validation.php

class-base-validation.php in Parse.ly 3.20.1, at src/rest-api/class-base-validation.php

51 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Base Validation class for REST API parameters
4 *
5 * @package Parsely
6 * @since 3.19.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\REST_API;
12
13 use WP_REST_Request;
14 use WP_Error;
15
16 /**
17 * Base class for validating REST API parameters.
18 *
19 * @since 3.19.0
20 */
21 abstract class Base_Validation {
22 /**
23 * Validates a parameter.
24 *
25 * @since 3.19.0
26 *
27 * @param mixed $param The parameter value.
28 * @param WP_REST_Request $request The request object.
29 * @return true|WP_Error Whether the parameter is valid.
30 */
31 abstract public static function validate( $param, WP_REST_Request $request );
32
33 /**
34 * Sanitizes a parameter.
35 *
36 * If a sanitize method is not implemented, it will throw an exception.
37 *
38 * @since 3.19.0
39 *
40 * @throws \Exception The sanitize method is not implemented.
41 *
42 * @param mixed $value The value to sanitize.
43 * @param WP_REST_Request $request The request object.
44 * @param string $param The parameter name.
45 * @return mixed The sanitized value.
46 */
47 public static function sanitize( $value, $request, $param ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
48 throw new \Exception( 'Trying to sanitize ' . esc_html( $param ) . ' parameter without a sanitize method.' );
49 }
50 }
51