| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Requests\FrontendRequests; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
|
| 7 |
/** |
| 8 |
* RequestGuard forwards unknown calls to the wrapped request via __call(), and its |
| 9 |
* $request property is protected with no accessor. Declaring the forwarded methods |
| 10 |
* we actually use keeps static analysis honest about calls that resolve at runtime. |
| 11 |
* |
| 12 |
* @method string|null get_header(string $key) |
| 13 |
*/ |
| 14 |
class ReviewRequest extends RequestGuard |
| 15 |
{ |
| 16 |
public function rules(): array |
| 17 |
{ |
| 18 |
return [ |
| 19 |
'rating' => 'nullable|numeric|min:1|max:5', |
| 20 |
'title' => 'nullable|sanitizeText|maxLength:192', |
| 21 |
'content' => 'nullable|maxLength:5000', |
| 22 |
'reviewer_name' => 'nullable|sanitizeText|maxLength:100', |
| 23 |
'reviewer_email' => 'nullable|sanitizeText|email|maxLength:192', |
| 24 |
// The order-review page's proof of purchase: an order uuid. Bounded |
| 25 |
// here so a junk value is rejected before it reaches a query. |
| 26 |
'order_hash' => 'nullable|sanitizeText|maxLength:64', |
| 27 |
// The variation the review is about. Only honoured alongside an |
| 28 |
// order grant that covers that item; the controller forces 0 |
| 29 |
// otherwise. |
| 30 |
'item_id' => 'nullable|numeric', |
| 31 |
'per_page' => 'nullable|numeric|min:1|max:50', |
| 32 |
'sort_by' => 'nullable|sanitizeText|maxLength:50', |
| 33 |
'sort_order' => 'nullable|sanitizeText|maxLength:10', |
| 34 |
'has_media' => 'nullable|numeric', |
| 35 |
'verified_only' => 'nullable|numeric', |
| 36 |
// Display flags are sent again when Reviews.js refreshes a page, |
| 37 |
// so the endpoint renders the same preset after sorting or |
| 38 |
// pagination. Keep them constrained to the wire's 0/1 shape. |
| 39 |
'show_avatar' => 'nullable|numeric|min:0|max:1', |
| 40 |
'show_title' => 'nullable|numeric|min:0|max:1', |
| 41 |
'show_content' => 'nullable|numeric|min:0|max:1', |
| 42 |
'show_photos' => 'nullable|numeric|min:0|max:1', |
| 43 |
'show_footer' => 'nullable|numeric|min:0|max:1', |
| 44 |
'show_variation' => 'nullable|numeric|min:0|max:1', |
| 45 |
'page' => 'nullable|numeric|min:1', |
| 46 |
'client_id' => 'nullable|sanitizeText|maxLength:64', |
| 47 |
'max_words' => 'nullable|numeric|min:0|max:500', |
| 48 |
'pagination_type'=> 'nullable|sanitizeText|maxLength:20', |
| 49 |
'media_visible' => 'nullable|numeric|min:0|max:100', |
| 50 |
'media_width' => 'nullable|numeric|min:0|max:2000', |
| 51 |
'media_height' => 'nullable|numeric|min:0|max:2000', |
| 52 |
'media_full_width'=> 'nullable|numeric|min:0|max:1', |
| 53 |
'media_flush' => 'nullable|numeric|min:0|max:1', |
| 54 |
'media_backdrop' => 'nullable|numeric|min:0|max:1', |
| 55 |
'photos_first' => 'nullable|numeric|min:0|max:1', |
| 56 |
'rating_first' => 'nullable|numeric|min:0|max:1', |
| 57 |
'badge_last' => 'nullable|numeric|min:0|max:1', |
| 58 |
'show_meta' => 'nullable|numeric|min:0|max:1', |
| 59 |
'item_class' => 'nullable|string', |
| 60 |
'media_more' => 'nullable|sanitizeText|maxLength:20', |
| 61 |
]; |
| 62 |
} |
| 63 |
|
| 64 |
public function messages(): array |
| 65 |
{ |
| 66 |
return [ |
| 67 |
'rating.numeric' => esc_html__('Rating must be a number.', 'fluent-cart'), |
| 68 |
'rating.min' => esc_html__('Rating must be at least 1.', 'fluent-cart'), |
| 69 |
'rating.max' => esc_html__('Rating must not exceed 5.', 'fluent-cart'), |
| 70 |
'title.maxLength' => esc_html__('Review title must not exceed 192 characters.', 'fluent-cart'), |
| 71 |
'content.required' => esc_html__('Review content is required.', 'fluent-cart'), |
| 72 |
'content.maxLength' => esc_html__('Review content must not exceed 5000 characters.', 'fluent-cart'), |
| 73 |
]; |
| 74 |
} |
| 75 |
|
| 76 |
public function sanitize(): array |
| 77 |
{ |
| 78 |
return [ |
| 79 |
'rating' => 'intval', |
| 80 |
'title' => 'sanitize_text_field', |
| 81 |
'content' => 'sanitize_textarea_field', |
| 82 |
'reviewer_name' => 'sanitize_text_field', |
| 83 |
'reviewer_email' => 'sanitize_email', |
| 84 |
'order_hash' => 'sanitize_text_field', |
| 85 |
'item_id' => 'intval', |
| 86 |
'per_page' => 'intval', |
| 87 |
'sort_by' => 'sanitize_text_field', |
| 88 |
'sort_order' => 'sanitize_text_field', |
| 89 |
'has_media' => 'intval', |
| 90 |
'verified_only' => 'intval', |
| 91 |
'show_avatar' => 'intval', |
| 92 |
'show_title' => 'intval', |
| 93 |
'show_content' => 'intval', |
| 94 |
'show_photos' => 'intval', |
| 95 |
'show_footer' => 'intval', |
| 96 |
'show_variation' => 'intval', |
| 97 |
'page' => 'intval', |
| 98 |
'client_id' => 'sanitize_text_field', |
| 99 |
'max_words' => 'intval', |
| 100 |
'pagination_type'=> 'sanitize_text_field', |
| 101 |
'media_visible' => 'intval', |
| 102 |
'media_width' => 'intval', |
| 103 |
'media_height' => 'intval', |
| 104 |
'media_full_width'=> 'intval', |
| 105 |
'media_flush' => 'intval', |
| 106 |
'media_backdrop' => 'intval', |
| 107 |
'photos_first' => 'intval', |
| 108 |
'rating_first' => 'intval', |
| 109 |
'badge_last' => 'intval', |
| 110 |
'show_meta' => 'intval', |
| 111 |
'item_class' => 'sanitize_html_class', |
| 112 |
'media_more' => 'sanitize_text_field', |
| 113 |
]; |
| 114 |
} |
| 115 |
} |
| 116 |
|