1 | <?php |
||
14 | trait FluentMeta |
||
15 | { |
||
16 | use Metable; |
||
17 | |||
18 | /** |
||
19 | * Model table columns. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | public static $model_table_columns = []; |
||
24 | |||
25 | /** |
||
26 | * Get a models table columns. |
||
27 | * |
||
28 | * @param $class |
||
29 | * @return mixed |
||
30 | */ |
||
31 | protected function getClassColumns($class) |
||
41 | |||
42 | /** |
||
43 | * Check whether a method, property or attribute |
||
44 | * name exists on the model. |
||
45 | * |
||
46 | * @param $name |
||
47 | * @return bool |
||
48 | */ |
||
49 | protected function existsOnParent($name) |
||
57 | |||
58 | /** |
||
59 | * Dynamically determine whether a meta item or model property isset. |
||
60 | * |
||
61 | * @param $name |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function __isset($name) |
||
72 | |||
73 | /** |
||
74 | * Dynamically get a model property / attribute or meta item. |
||
75 | * |
||
76 | * @param $name |
||
77 | * @return mixed |
||
78 | */ |
||
79 | public function __get($name) |
||
89 | |||
90 | /** |
||
91 | * Dynamically set a meta item or model property / attribute. |
||
92 | * |
||
93 | * @param $name |
||
94 | * @param $value |
||
95 | * @return mixed |
||
96 | */ |
||
97 | public function __set($name, $value) |
||
105 | |||
106 | /** |
||
107 | * Dynamically unset a meta item or model property / attribute. |
||
108 | * |
||
109 | * @param $name |
||
110 | */ |
||
111 | public function __unset($name) |
||
123 | } |
||
124 |
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.