1 | <?php |
||
9 | trait HasOptions |
||
10 | { |
||
11 | protected $options = []; |
||
12 | |||
13 | protected $optionsLabelAttribute; |
||
14 | |||
15 | protected $optionsValueAttribute; |
||
16 | |||
17 | protected function isOptionsModel() |
||
21 | |||
22 | protected function isRelation() |
||
26 | |||
27 | public function getOptions() |
||
46 | |||
47 | protected function parseOptions($options) |
||
51 | |||
52 | /** |
||
53 | * @param mixed $options |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | public function setOptions($options) |
||
63 | |||
64 | /** |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | protected function setOptionsFromModel() |
||
89 | |||
90 | /** |
||
91 | * @return Model |
||
92 | */ |
||
93 | public function getOptionsModel() |
||
113 | |||
114 | /** |
||
115 | * 获取 options 标题字段 |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | public function getOptionsLabelAttribute() |
||
123 | |||
124 | /** |
||
125 | * 设置 options 标题字段 |
||
126 | * |
||
127 | * @param string $value |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | public function setOptionsLabelAttribute($value) |
||
137 | |||
138 | /** |
||
139 | * 获取 options value 字段 |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getOptionsValueAttribute() |
||
147 | |||
148 | /** |
||
149 | * 设置 options value 字段 |
||
150 | * |
||
151 | * @param string $value |
||
152 | * |
||
153 | * @return $this |
||
154 | */ |
||
155 | public function setOptionsValueAttribute($value) |
||
161 | } |
||
162 |
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.