1 | <?php |
||
14 | trait OptionsTrait |
||
15 | { |
||
16 | /** |
||
17 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
18 | */ |
||
19 | protected $options = []; |
||
20 | |||
21 | /** |
||
22 | * Initialize options collection. |
||
23 | */ |
||
24 | protected function initializeOptions() |
||
30 | |||
31 | /** |
||
32 | * Get options. |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | public function getOptions() |
||
42 | |||
43 | /** |
||
44 | * Has option. |
||
45 | * |
||
46 | * @param string $option |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function hasOption($option) |
||
56 | |||
57 | /** |
||
58 | * Get option. |
||
59 | * |
||
60 | * @param string $option |
||
61 | * @param mixed $default |
||
62 | * |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function getOption($option, $default = null) |
||
71 | |||
72 | /** |
||
73 | * Set options. |
||
74 | * |
||
75 | * @param array $options |
||
76 | * |
||
77 | * @return $this |
||
78 | */ |
||
79 | public function setOptions($options) |
||
93 | |||
94 | /** |
||
95 | * Set option. |
||
96 | * |
||
97 | * @param string $option |
||
98 | * @param mixed $value |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | public function setOption($option, $value) |
||
110 | } |
||
111 |
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.