| 1 | <?php |
||
| 8 | trait AutoValidate |
||
| 9 | {
|
||
| 10 | /** |
||
| 11 | * An array of validation rules |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | protected $rules = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * An array of validation messages |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | protected $messages = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Validates the Model |
||
| 24 | * @return boolean Whether or not the input is valid |
||
| 25 | */ |
||
| 26 | public function validate() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Returns an array of validation rules |
||
| 43 | * @return array An Array of validation rules |
||
| 44 | */ |
||
| 45 | protected function getValidationRules() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Returns an array of validation messages |
||
| 52 | * @return array An Array of validation messages |
||
| 53 | */ |
||
| 54 | protected function getValidationMessages() |
||
| 58 | } |
||
| 59 |
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
Idableprovides a methodequalsIdthat 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.