1 | <?php |
||
14 | abstract class InputValidator |
||
15 | { |
||
16 | /** |
||
17 | * Customise the messages returned. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $messages = [ |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * Returns array of rules of the format field => rule. |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | abstract public function getRules(); |
||
30 | |||
31 | /** |
||
32 | * Validate an array of data. |
||
33 | * |
||
34 | * @param array $data The array of data to validate. |
||
35 | * @return boolean |
||
36 | * @throws InputValidationException If validation fails. |
||
37 | */ |
||
38 | public function valid(array $data) |
||
61 | |||
62 | /** |
||
63 | * Validate an instance of a model. |
||
64 | * |
||
65 | * @param MappableModel $model The model to validate. |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function validateModel(MappableModel $model) |
||
72 | |||
73 | /** |
||
74 | * Set custom templates for messages. |
||
75 | * |
||
76 | * @param array $messages |
||
77 | * |
||
78 | * @return $this |
||
79 | */ |
||
80 | public function setMessages(array $messages) |
||
85 | |||
86 | /** |
||
87 | * Sets the message template on the exception if it has been configured. |
||
88 | * |
||
89 | * @param ValidationException $e The exception to add message to. |
||
90 | * |
||
91 | * @return static |
||
92 | */ |
||
93 | protected function formatMessage(ValidationException $e) |
||
103 | } |
||
104 |