1 | <?php |
||
12 | trait Validable |
||
13 | { |
||
14 | /** |
||
15 | * Validation switch. |
||
16 | * |
||
17 | * @var boolean |
||
18 | */ |
||
19 | protected $skipValidation = false; |
||
20 | |||
21 | /** |
||
22 | * Validator instance. |
||
23 | * |
||
24 | * @var \Illuminate\Contracts\Validation\Validator |
||
25 | */ |
||
26 | protected $validator; |
||
27 | |||
28 | /** |
||
29 | * Validator factory instance. |
||
30 | * |
||
31 | * @var \Illuminate\Contracts\Validation\Factory |
||
32 | */ |
||
33 | protected static $validatorFactory; |
||
34 | |||
35 | /** |
||
36 | * All the validation rules for this model. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected static $rulesMerged; |
||
41 | |||
42 | /** |
||
43 | * Register hooks for the trait. |
||
44 | * |
||
45 | * @codeCoverageIgnore |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | public static function bootValidable() |
||
59 | |||
60 | /** |
||
61 | * Determine whether all the attributes on this instance pass validation. |
||
62 | * |
||
63 | * @return boolean |
||
64 | */ |
||
65 | public function isValid() |
||
71 | |||
72 | /** |
||
73 | * Skip validation on the next saving attempt. |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function skipValidation() |
||
81 | |||
82 | /** |
||
83 | * Disable validation for this instance. |
||
84 | * |
||
85 | * @return $this |
||
86 | */ |
||
87 | public function disableValidation($once = false) |
||
93 | |||
94 | /** |
||
95 | * Enable validation for this instance. |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function enableValidation() |
||
105 | |||
106 | /** |
||
107 | * Get current validation flag. |
||
108 | * |
||
109 | * @return integer|false |
||
110 | */ |
||
111 | public function skipsValidation() |
||
115 | |||
116 | /** |
||
117 | * Determine whether validation is enabled for this instance. |
||
118 | * |
||
119 | * @return boolean |
||
120 | */ |
||
121 | public function validationEnabled() |
||
125 | |||
126 | /** |
||
127 | * Retrieve validation error messages. |
||
128 | * |
||
129 | * @return \Illuminate\Support\MessageBag |
||
130 | */ |
||
131 | public function getValidationErrors() |
||
135 | |||
136 | /** |
||
137 | * Retrieve validation error messages. |
||
138 | * |
||
139 | * @return \Illuminate\Support\MessageBag |
||
140 | */ |
||
141 | public function getMessageBag() |
||
145 | |||
146 | /** |
||
147 | * Get names of the attributes that didn't pass validation. |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | public function getInvalidAttributes() |
||
155 | |||
156 | /** |
||
157 | * Get the validator instance. |
||
158 | * |
||
159 | * @return \Illuminate\Contracts\Validation\Validator |
||
160 | */ |
||
161 | public function getValidator() |
||
174 | |||
175 | /** |
||
176 | * Get custom validation messages. |
||
177 | * |
||
178 | * @return array |
||
179 | */ |
||
180 | public static function getValidationMessages() |
||
186 | |||
187 | /** |
||
188 | * Get custom validation attribute names. |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | public static function getValidationAttributes() |
||
198 | |||
199 | /** |
||
200 | * Get all the validation rules for this model. |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | public static function getCreateRules() |
||
212 | |||
213 | /** |
||
214 | * Gather all the rules for the model and store it for easier use. |
||
215 | * |
||
216 | * @return array |
||
217 | */ |
||
218 | protected static function gatherRules() |
||
253 | |||
254 | /** |
||
255 | * Get all validation rules for update on this model. |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | public function getUpdateRules() |
||
263 | |||
264 | /** |
||
265 | * Get all validation rules for update for given id. |
||
266 | * |
||
267 | * @param \Illuminate\Database\Eloquent\Model|integer|string $id |
||
268 | * @return array |
||
269 | */ |
||
270 | public static function getUpdateRulesForId($id) |
||
274 | |||
275 | /** |
||
276 | * Get array of attributes that have validation rules defined. |
||
277 | * |
||
278 | * @return array |
||
279 | */ |
||
280 | public static function getValidatedFields() |
||
290 | |||
291 | /** |
||
292 | * Get all the rules groups defined on this model. |
||
293 | * |
||
294 | * @return array |
||
295 | */ |
||
296 | protected static function getRulesGroups() |
||
308 | |||
309 | /** |
||
310 | * Get rules from given group. |
||
311 | * |
||
312 | * @param string $group |
||
313 | * @return array |
||
314 | */ |
||
315 | protected static function getRulesGroup($group) |
||
319 | |||
320 | /** |
||
321 | * Set validation factory instance for this model. |
||
322 | * |
||
323 | * @param \Illuminate\Contracts\Validation\Factory |
||
324 | * @return void |
||
325 | */ |
||
326 | public static function setValidatorFactory(Factory $factory) |
||
330 | } |
||
331 |
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.