1 | <?php |
||
11 | trait FieldWithOptions |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $options; |
||
17 | |||
18 | /** |
||
19 | * @var mixed |
||
20 | */ |
||
21 | protected $default_option = null; |
||
22 | |||
23 | /** |
||
24 | * @param array $options |
||
25 | * @param mixed $default The default value. It's a key from given options. |
||
26 | * @return self |
||
27 | */ |
||
28 | public function withOptions($options = [], $default = null) |
||
46 | |||
47 | /** |
||
48 | * @param mixed $identifier |
||
49 | * @return bool |
||
50 | */ |
||
51 | public function hasOption($identifier) |
||
55 | |||
56 | /** |
||
57 | * @param void |
||
58 | * @return array |
||
59 | */ |
||
60 | public function getOptions() |
||
64 | |||
65 | /** |
||
66 | * @param void |
||
67 | * @return array |
||
68 | */ |
||
69 | public function getOptionsKeys() |
||
73 | |||
74 | /** |
||
75 | * @param void |
||
76 | * @return string|null |
||
77 | */ |
||
78 | public function getOption($identifier) |
||
82 | |||
83 | /** |
||
84 | * @param void |
||
85 | * @return mixed |
||
86 | */ |
||
87 | public function getDefaultOption() |
||
91 | |||
92 | /** |
||
93 | * @param void |
||
94 | * @return string|null |
||
95 | */ |
||
96 | public function getTableValue() |
||
100 | |||
101 | /** |
||
102 | * @param void |
||
103 | * @return self |
||
104 | */ |
||
105 | public function beforeSave() |
||
114 | } |
||
115 |
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.