1 | <?php |
||
26 | abstract class AbstractFieldValidator extends AbstractValidator |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * Fill with paths to JavaScript files containing validation code. They will |
||
31 | * be automatically imported when needed. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected static $javaScriptValidationFiles = []; |
||
36 | |||
37 | /** |
||
38 | * List of supported messages, which are used whenever an error occurs. |
||
39 | * Can be overridden with TypoScript in the validator configuration. |
||
40 | * |
||
41 | * Example: |
||
42 | * $supportedMessages = [ |
||
43 | * 'default' => [ |
||
44 | * 'key' => 'path.to.my.message', |
||
45 | * 'extension' => 'extension_containing_message', |
||
46 | * 'value' => 'Some value' // Static value of the message, not recommended though. |
||
47 | * ] |
||
48 | * ] |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $supportedMessages = []; |
||
53 | |||
54 | /** |
||
55 | * Set this to true if you want to be able to add any message you want. |
||
56 | * |
||
57 | * @var bool |
||
58 | */ |
||
59 | protected $supportsAllMessages = false; |
||
60 | |||
61 | /** |
||
62 | * Contains the original form instance. |
||
63 | * |
||
64 | * @var FormInterface |
||
65 | */ |
||
66 | protected $form; |
||
67 | |||
68 | /** |
||
69 | * Contains the merge of the supported messages and the TypoScript defined |
||
70 | * messages. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $messages = []; |
||
75 | |||
76 | /** |
||
77 | * Array of arbitrary data which can be added by child classes, and will |
||
78 | * then be added to the `$validationData` property of the form instance. |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | protected $validationData = []; |
||
83 | |||
84 | /** |
||
85 | * @var ValidatorDataObject |
||
86 | */ |
||
87 | protected $dataObject; |
||
88 | |||
89 | /** |
||
90 | * Constructs the validator, sets validation options and messages. |
||
91 | * |
||
92 | * @param array $options Options for the validator. |
||
93 | * @param ValidatorDataObject $dataObject |
||
94 | */ |
||
95 | final public function __construct(array $options = [], ValidatorDataObject $dataObject) |
||
107 | |||
108 | /** |
||
109 | * Creates a new validation error and adds it to the result. |
||
110 | * |
||
111 | * @param string $key |
||
112 | * @param int $code |
||
113 | * @param array $arguments |
||
114 | * @param string $title |
||
115 | */ |
||
116 | protected function addError($key, $code, array $arguments = [], $title = '') |
||
121 | |||
122 | /** |
||
123 | * Creates a new validation warning and adds it to the result. |
||
124 | * |
||
125 | * @param string $key |
||
126 | * @param int $code |
||
127 | * @param array $arguments |
||
128 | * @param string $title |
||
129 | */ |
||
130 | protected function addWarning($key, $code, array $arguments = [], $title = '') |
||
135 | |||
136 | /** |
||
137 | * Creates a new validation notice and adds it to the result. |
||
138 | * |
||
139 | * @param string $key |
||
140 | * @param int $code |
||
141 | * @param array $arguments |
||
142 | * @param string $title |
||
143 | */ |
||
144 | protected function addNotice($key, $code, array $arguments = [], $title = '') |
||
149 | |||
150 | /** |
||
151 | * Get the full validation data. |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | public function getValidationData() |
||
159 | |||
160 | /** |
||
161 | * Refreshes entirely the validation data (see `setValidationDataValue()`). |
||
162 | * |
||
163 | * @param array $validationData |
||
164 | */ |
||
165 | protected function setValidationData(array $validationData) |
||
169 | |||
170 | /** |
||
171 | * Adds an arbitrary value to the validator, which will be added to the |
||
172 | * `$validationData` property of the form. |
||
173 | * |
||
174 | * @param string $key Key of the data. |
||
175 | * @param mixed $value Value bound to the key. |
||
176 | */ |
||
177 | protected function setValidationDataValue($key, $value) |
||
181 | |||
182 | /** |
||
183 | * @param string $type |
||
184 | * @param string $key |
||
185 | * @param string $code |
||
186 | * @param array $arguments |
||
187 | * @param string $title |
||
188 | * @return mixed |
||
189 | * @throws EntryNotFoundException |
||
190 | */ |
||
191 | private function addMessage($type, $key, $code, array $arguments, $title) |
||
206 | |||
207 | /** |
||
208 | * This function should *always* be used when a message should be translated |
||
209 | * when an error occurs in the validation process. |
||
210 | * |
||
211 | * @param string $key The key of the message, usually "default". |
||
212 | * @param array $arguments Arguments given to the message. |
||
213 | * @return string |
||
214 | */ |
||
215 | private function getMessage($key, array $arguments = []) |
||
219 | |||
220 | /** |
||
221 | * @return array |
||
222 | */ |
||
223 | public static function getJavaScriptValidationFiles() |
||
227 | } |
||
228 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.