1 | <?php |
||
7 | trait HasAttributesTrait |
||
8 | { |
||
9 | |||
10 | 41 | protected function ensureAttributes() |
|
16 | |||
17 | /** |
||
18 | * Retrieve all of the label's attributes |
||
19 | * |
||
20 | * @return mixed |
||
21 | */ |
||
22 | 2 | public function getAttributes() |
|
28 | |||
29 | /** |
||
30 | * Sets multiple attributes for the label |
||
31 | * |
||
32 | * @param array $attrs |
||
33 | * |
||
34 | * @return HasAttributesTrait |
||
|
|||
35 | */ |
||
36 | 9 | public function setAttributes($attrs) |
|
43 | |||
44 | /** |
||
45 | * Retrieve an attribute from the label |
||
46 | * |
||
47 | * @param string $attr |
||
48 | * |
||
49 | * @return mixed |
||
50 | */ |
||
51 | 3 | public function getAttribute($attr) |
|
57 | |||
58 | /** |
||
59 | * Set/Unset a label attribute |
||
60 | * |
||
61 | * @param string $attr |
||
62 | * @param string $value |
||
63 | * |
||
64 | * @return self |
||
65 | */ |
||
66 | 35 | public function setAttribute($attr, $value = null) |
|
73 | |||
74 | /** |
||
75 | * Adds a CSS class to the label's "class" attribute |
||
76 | * |
||
77 | * @param string $class |
||
78 | * |
||
79 | * @return self |
||
80 | */ |
||
81 | 1 | public function addClass($class) |
|
88 | |||
89 | /** |
||
90 | * Removes a CSS class from the label's "class" attribute |
||
91 | * |
||
92 | * @param string $class |
||
93 | * |
||
94 | * @return self |
||
95 | */ |
||
96 | 1 | public function removeClass($class) |
|
103 | |||
104 | /** |
||
105 | * Toggles a CSS class to the label's "class" attribute |
||
106 | * |
||
107 | * @param |
||
108 | * $class |
||
109 | * |
||
110 | * @return self |
||
111 | */ |
||
112 | 1 | public function toggleClass($class) |
|
119 | |||
120 | /** |
||
121 | * Checks if the label has a CSS class on the "class" attribute |
||
122 | * |
||
123 | * @param |
||
124 | * $class |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | 2 | public function hasClass($class) |
|
134 | |||
135 | } |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.