| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Requests\ProductDownloadable; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
|
| 7 |
class ProductDownloadableFileRequest extends RequestGuard |
| 8 |
{ |
| 9 |
|
| 10 |
/** |
| 11 |
* @return array |
| 12 |
*/ |
| 13 |
public function rules() |
| 14 |
{ |
| 15 |
|
| 16 |
return [ |
| 17 |
//'product_variation_id' => 'required|array|min:1', |
| 18 |
'title' => 'required|sanitizeText|maxLength:100', |
| 19 |
'type' => 'required|sanitizeText|maxLength:100', |
| 20 |
'driver' => 'required|sanitizeText|maxLength:100', |
| 21 |
'file_name' => 'required|sanitizeText|maxLength:100', |
| 22 |
'settings.download_limit' => 'nullable|numeric', |
| 23 |
'settings.download_expiry' => 'nullable|numeric', |
| 24 |
]; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* @return array |
| 30 |
*/ |
| 31 |
public function messages(): array |
| 32 |
{ |
| 33 |
return [ |
| 34 |
'title.required' => esc_html__('Title is required.', 'fluent-cart'), |
| 35 |
'type.required' => esc_html__('Type is required.', 'fluent-cart'), |
| 36 |
'driver.required' => esc_html__('Driver is required.', 'fluent-cart'), |
| 37 |
'file_name.required' => esc_html__('File Name is required.', 'fluent-cart'), |
| 38 |
'file_path.required' => esc_html__('File Path is required.', 'fluent-cart'), |
| 39 |
'file_url.required' => esc_html__('File URL is required.', 'fluent-cart'), |
| 40 |
]; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
/** |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function sanitize() |
| 48 |
{ |
| 49 |
|
| 50 |
return [ |
| 51 |
'id' => 'intval', |
| 52 |
//'post_id' => 'intval', |
| 53 |
'product_variation_id' => function ($value) { |
| 54 |
if (!is_array($value)) { |
| 55 |
return []; |
| 56 |
} |
| 57 |
return array_values(array_filter(array_map(function ($id) { |
| 58 |
return sanitize_text_field($id); |
| 59 |
}, $value))); |
| 60 |
}, |
| 61 |
//'download_identifier' => 'sanitize_text_field', |
| 62 |
'title' => 'sanitize_text_field', |
| 63 |
'type' => 'sanitize_text_field', |
| 64 |
'driver' => 'sanitize_text_field', |
| 65 |
'file_name' => 'sanitize_text_field', |
| 66 |
'file_path' => 'sanitize_text_field', |
| 67 |
'file_url' => 'sanitize_text_field', |
| 68 |
'settings' => function ($value) { |
| 69 |
return $value; |
| 70 |
}, |
| 71 |
'serial' => 'intval', |
| 72 |
//'created_at' => 'sanitize_text_field', |
| 73 |
//'updated_at' => 'sanitize_text_field', |
| 74 |
]; |
| 75 |
|
| 76 |
} |
| 77 |
} |
| 78 |
|