| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Http\Requests; |
| 4 |
|
| 5 |
use FluentSupport\Framework\Foundation\RequestGuard; |
| 6 |
|
| 7 |
class TicketResponseRequest extends RequestGuard |
| 8 |
{ |
| 9 |
/** |
| 10 |
* @return array |
| 11 |
*/ |
| 12 |
public function rules() |
| 13 |
{ |
| 14 |
return [ |
| 15 |
'content' => 'required' |
| 16 |
]; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* @return array |
| 21 |
*/ |
| 22 |
public function messages() |
| 23 |
{ |
| 24 |
return [ |
| 25 |
'content.required' => __('Reply content is required', 'fluent-support') |
| 26 |
]; |
| 27 |
} |
| 28 |
|
| 29 |
public function sanitize() |
| 30 |
{ |
| 31 |
$data = $this->all(); |
| 32 |
|
| 33 |
$sanitizeRules = [ |
| 34 |
'content' => 'wp_kses_post', |
| 35 |
'conversation_type' => 'sanitize_text_field', |
| 36 |
'close_ticket' => 'sanitize_text_field', |
| 37 |
'ticket_id' => 'intval', |
| 38 |
'informational_reply' => 'rest_sanitize_boolean' |
| 39 |
]; |
| 40 |
|
| 41 |
if( $data && is_array($data) ) { |
| 42 |
foreach ($data as $dataKey => $dataItem) { |
| 43 |
$sanitizeFunc = isset($sanitizeRules[$dataKey]) ? $sanitizeRules[$dataKey]: 'sanitize_text_field'; |
| 44 |
|
| 45 |
if(is_array($dataItem)) { |
| 46 |
$data[$dataKey] = map_deep($dataItem, $sanitizeFunc); |
| 47 |
} else { |
| 48 |
$data[$dataKey] = $sanitizeFunc($dataItem); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return $data; |
| 53 |
} |
| 54 |
|
| 55 |
return sanitize_text_field($data); |
| 56 |
} |
| 57 |
} |
| 58 |
|