1 | <?php |
||
11 | trait HasModelTrait |
||
12 | { |
||
13 | /** |
||
14 | * @var Record |
||
15 | */ |
||
16 | protected $model; |
||
17 | |||
18 | /** |
||
19 | * @param $name |
||
20 | * @return $this |
||
21 | */ |
||
22 | public function addModelError($name) |
||
26 | |||
27 | /** |
||
28 | * @param $name |
||
29 | * @param array $variables |
||
30 | * @return mixed |
||
31 | */ |
||
32 | public function getModelMessage($name, $variables = []) |
||
36 | |||
37 | /** |
||
38 | * @return Record |
||
39 | */ |
||
40 | public function getModel() |
||
44 | |||
45 | /** |
||
46 | * @param Record $model |
||
47 | * @return $this |
||
48 | */ |
||
49 | public function setModel(Record $model) |
||
56 | |||
57 | protected function getDataFromModel() |
||
68 | |||
69 | /** |
||
70 | * @param $input |
||
71 | * @param $name |
||
72 | * @param array $variables |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function addInputModelError($input, $name, $variables = []) |
||
79 | |||
80 | /** |
||
81 | * @param $name |
||
82 | * @return mixed |
||
83 | */ |
||
84 | public function getModelLabel($name) |
||
88 | |||
89 | /** |
||
90 | * @return \Nip\Records\RecordManager |
||
91 | */ |
||
92 | public function getModelManager() |
||
96 | |||
97 | public function process() |
||
102 | |||
103 | public function saveToModel() |
||
112 | |||
113 | public function saveModel() |
||
117 | |||
118 | protected function _addModelFormMessage($form, $model) |
||
124 | } |
||
125 |
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.