| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Requests; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
|
| 7 |
class CartRequest extends RequestGuard |
| 8 |
{ |
| 9 |
/** |
| 10 |
* @return array |
| 11 |
*/ |
| 12 |
public function rules() |
| 13 |
{ |
| 14 |
return [ |
| 15 |
'customer_id' => 'integer', |
| 16 |
'user_id' => 'integer', |
| 17 |
'order_id' => 'integer', |
| 18 |
'cart_hash' => 'sanitizeText', |
| 19 |
'checkout_data' => 'sanitizeTextArea|maxLength:255', |
| 20 |
'cart_data' => 'sanitizeTextArea', |
| 21 |
'first_name' => 'sanitizeText|maxLength:255', |
| 22 |
'last_name' => 'sanitizeText|maxLength:255', |
| 23 |
'email' => 'sanitizeText|maxLength:255', |
| 24 |
'stage' => 'sanitizeText|maxLength:30', |
| 25 |
'cart_group' => 'sanitizeText|maxLength:30', |
| 26 |
]; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* |
| 31 |
* @return array |
| 32 |
*/ |
| 33 |
public function messages() |
| 34 |
{ |
| 35 |
return [ |
| 36 |
'customer_id' => esc_html__('Customer Id must be a number.', 'fluent-cart'), |
| 37 |
'user_id' => esc_html__('User Id must be a number.', 'fluent-cart'), |
| 38 |
]; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
/** |
| 43 |
* |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
public function sanitize() |
| 47 |
{ |
| 48 |
return [ |
| 49 |
'first_name' => 'sanitize_text_field', |
| 50 |
'last_name' => 'sanitize_text_field', |
| 51 |
'email' => function ($value) { |
| 52 |
if(empty($value)) { |
| 53 |
return ''; |
| 54 |
} |
| 55 |
|
| 56 |
return sanitize_email($value); |
| 57 |
}, |
| 58 |
]; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|