1 | <?php |
||
13 | abstract class Validator extends Object |
||
14 | { |
||
15 | |||
16 | public function __construct() |
||
21 | |||
22 | /** |
||
23 | * @var Form $form |
||
24 | */ |
||
25 | protected $form; |
||
26 | |||
27 | /** |
||
28 | * @var ValidationResult $result |
||
29 | */ |
||
30 | protected $result; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $enabled = true; |
||
36 | |||
37 | /** |
||
38 | * @param Form $form |
||
39 | * @return $this |
||
40 | */ |
||
41 | public function setForm($form) |
||
46 | |||
47 | /** |
||
48 | * Returns any errors there may be. |
||
49 | * |
||
50 | * @return ValidationResult |
||
51 | */ |
||
52 | public function validate() |
||
60 | |||
61 | /** |
||
62 | * Callback to register an error on a field (Called from implementations of |
||
63 | * {@link FormField::validate}). The optional error message type parameter is loaded into the |
||
64 | * HTML class attribute. |
||
65 | * |
||
66 | * See {@link getErrors()} for details. |
||
67 | * |
||
68 | * @param string $fieldName Field name for this error |
||
69 | * @param string $message The message string |
||
70 | * @param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS |
||
71 | * class to the form, so other values can be used if desired. |
||
72 | * @param string|bool $cast Cast type; One of the CAST_ constant definitions. |
||
73 | * Bool values will be treated as plain text flag. |
||
74 | * @return $this |
||
75 | */ |
||
76 | public function validationError( |
||
85 | |||
86 | /** |
||
87 | * Returns all errors found by a previous call to {@link validate()}. The returned array has a |
||
88 | * structure resembling: |
||
89 | * |
||
90 | * <code> |
||
91 | * array( |
||
92 | * 'fieldName' => '[form field name]', |
||
93 | * 'message' => '[validation error message]', |
||
94 | * 'messageType' => '[bad|message|validation|required]', |
||
95 | * 'messageCast' => '[text|html]' |
||
96 | * ) |
||
97 | * </code> |
||
98 | * |
||
99 | * @return null|array |
||
100 | */ |
||
101 | public function getErrors() |
||
108 | |||
109 | /** |
||
110 | * Get last validation result |
||
111 | * |
||
112 | * @return ValidationResult |
||
113 | */ |
||
114 | public function getResult() |
||
118 | |||
119 | /** |
||
120 | * Returns whether the field in question is required. This will usually display '*' next to the |
||
121 | * field. The base implementation always returns false. |
||
122 | * |
||
123 | * @param string $fieldName |
||
124 | * |
||
125 | * @return bool |
||
126 | */ |
||
127 | public function fieldIsRequired($fieldName) |
||
131 | |||
132 | /** |
||
133 | * @param array $data |
||
134 | * |
||
135 | * @return mixed |
||
136 | */ |
||
137 | abstract public function php($data); |
||
138 | |||
139 | /** |
||
140 | * @param bool $enabled |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setEnabled($enabled) |
||
148 | |||
149 | /** |
||
150 | * @return bool |
||
151 | */ |
||
152 | public function getEnabled() |
||
156 | |||
157 | /** |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function removeValidation() |
||
166 | |||
167 | /** |
||
168 | * Clear current result |
||
169 | * |
||
170 | * @return $this |
||
171 | */ |
||
172 | protected function resetResult() |
||
177 | } |
||
178 |