| 1 | <?php |
||
| 22 | abstract class AbstractRule |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Template for error output |
||
| 26 | * - {{name}} - name of field |
||
| 27 | * - {{input}} - input value |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $template = '{{name}} has invalid value {{input}}'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Check input data |
||
| 35 | * |
||
| 36 | * @param mixed $input |
||
| 37 | * @return bool |
||
| 38 | */ |
||
| 39 | abstract public function validate($input) : bool; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Invoke |
||
| 43 | * |
||
| 44 | * @param mixed $input |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | 1 | public function __invoke($input) : bool |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Assert |
||
| 54 | * |
||
| 55 | * @param string $input |
||
| 56 | * @return bool |
||
| 57 | * @throws ValidatorException |
||
| 58 | */ |
||
| 59 | 281 | public function assert($input) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Set error template |
||
| 69 | * |
||
| 70 | * @param string $template |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | public function setTemplate($template) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Get error template |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | 3 | public function getTemplate() |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Cast to string |
||
| 90 | * |
||
| 91 | * @return string |
||
| 92 | */ |
||
| 93 | 68 | public function __toString() |
|
| 97 | } |
||
| 98 |