Arrayable.php
3 years ago
HasBlockTheme.php
3 years ago
Objectable.php
1 year ago
SanitizesRestParams.php
2 months ago
SanitizesRestParams.php
29 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Concerns; |
| 4 | |
| 5 | /** |
| 6 | * Shared sanitization helpers for REST controllers that accept user-supplied |
| 7 | * filter parameters destined for DatabaseModel-backed query builders. |
| 8 | */ |
| 9 | trait SanitizesRestParams { |
| 10 | /** |
| 11 | * Coerce a user-supplied scalar filter value into a safe string or null. |
| 12 | * |
| 13 | * Returns null for null, empty-string, or any non-scalar input so that |
| 14 | * callers can filter out missing values before building a where clause. |
| 15 | * |
| 16 | * @param mixed $value Raw request value. |
| 17 | * @return string|null |
| 18 | */ |
| 19 | protected function sanitizeFilterParam( $value ) { |
| 20 | if ( null === $value || '' === $value ) { |
| 21 | return null; |
| 22 | } |
| 23 | if ( ! is_scalar( $value ) ) { |
| 24 | return null; |
| 25 | } |
| 26 | return sanitize_text_field( (string) $value ); |
| 27 | } |
| 28 | } |
| 29 |