| 1 | <?php |
||
| 10 | abstract class Validation |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Holds messages generated during validation. |
||
| 14 | * |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $messages = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param $field |
||
| 21 | * @param $data |
||
| 22 | * @return mixed |
||
| 23 | */ |
||
| 24 | abstract public function run($field, $data); |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Utility function that evaluates the result of a validation test and prepares validation messages. |
||
| 28 | * Receives a boolean from the validation function and a message to be displayed when the value is false. It also |
||
| 29 | * receives the options array so it could override the standard message that the validation code generates. |
||
| 30 | * |
||
| 31 | * @param array $field |
||
| 32 | * @param boolean $result |
||
| 33 | * @param string $message |
||
| 34 | * @return boolean |
||
| 35 | */ |
||
| 36 | 14 | protected function evaluateResult($field, $result, $message) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Extracts the value of the field description from the data passed. |
||
| 55 | * |
||
| 56 | * @param array $field |
||
| 57 | * @param array $data |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | 12 | protected function getFieldValue($field, $data) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Get the validation messages generated. |
||
| 71 | * |
||
| 72 | * @return array |
||
| 73 | */ |
||
| 74 | 14 | public function getMessages() |
|
| 78 | } |
||
| 79 |