1 | <?php |
||
9 | class Checkbox |
||
10 | { |
||
11 | use StringLength, ParserImporter, UtilImporter; |
||
12 | |||
13 | /** |
||
14 | * The value of the checkbox |
||
15 | * |
||
16 | * @var string|int|bool $value |
||
17 | */ |
||
18 | protected $value; |
||
19 | |||
20 | /** |
||
21 | * The label for the checkbox |
||
22 | * |
||
23 | * @var string|int $label |
||
24 | */ |
||
25 | protected $label; |
||
26 | |||
27 | /** |
||
28 | * Whether the checkbox is checked |
||
29 | * |
||
30 | * @var bool $checked |
||
31 | */ |
||
32 | protected $checked = false; |
||
33 | |||
34 | /** |
||
35 | * Whether pointer is currently pointing at the checkbox |
||
36 | * |
||
37 | * @var bool $current |
||
38 | */ |
||
39 | protected $current = false; |
||
40 | |||
41 | /** |
||
42 | * Whether the checkbox is the first in the group |
||
43 | * |
||
44 | * @var bool $first |
||
45 | */ |
||
46 | protected $first = false; |
||
47 | |||
48 | /** |
||
49 | * Whether the checkbox is the last in the group |
||
50 | * |
||
51 | * @var bool $last |
||
52 | */ |
||
53 | protected $last = false; |
||
54 | |||
55 | 16 | public function __construct($label, $value) |
|
60 | |||
61 | /** |
||
62 | * @return bool |
||
63 | */ |
||
64 | 16 | public function isCurrent() |
|
68 | |||
69 | /** |
||
70 | * @return bool |
||
71 | */ |
||
72 | 16 | public function isChecked() |
|
76 | |||
77 | /** |
||
78 | * @return bool |
||
79 | */ |
||
80 | 16 | public function isFirst() |
|
84 | |||
85 | /** |
||
86 | * @return bool |
||
87 | */ |
||
88 | 16 | public function isLast() |
|
92 | |||
93 | /** |
||
94 | * Set whether the pointer is currently pointing at this checkbox |
||
95 | * |
||
96 | * @param bool $current |
||
97 | * |
||
98 | * @return Checkbox |
||
99 | */ |
||
100 | 16 | public function setCurrent($current = true) |
|
106 | |||
107 | /** |
||
108 | * Set whether the checkbox is currently checked |
||
109 | * |
||
110 | * @param bool $checked |
||
111 | * |
||
112 | * @return Checkbox |
||
113 | */ |
||
114 | 16 | public function setChecked($checked = true) |
|
120 | |||
121 | /** |
||
122 | * @return Checkbox |
||
123 | */ |
||
124 | 16 | public function setFirst() |
|
130 | |||
131 | /** |
||
132 | * @return Checkbox |
||
133 | */ |
||
134 | 16 | public function setLast() |
|
140 | |||
141 | /** |
||
142 | * @return string|int|bool |
||
143 | */ |
||
144 | 12 | public function getValue() |
|
148 | |||
149 | /** |
||
150 | * Build out basic checkbox string based on current options |
||
151 | * |
||
152 | * @return string |
||
153 | */ |
||
154 | 16 | protected function buildCheckboxString() |
|
166 | |||
167 | /** |
||
168 | * Get the padding string based on the length of the terminal/line |
||
169 | * |
||
170 | * @param string $line |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | 16 | protected function getPaddingString($line) |
|
183 | |||
184 | /** |
||
185 | * Get the checkbox symbol |
||
186 | * |
||
187 | * @param bool $checked |
||
188 | 16 | * |
|
189 | * @return string |
||
190 | 16 | */ |
|
191 | 16 | protected function checkbox($checked) |
|
199 | |||
200 | /** |
||
201 | * Get the pointer symbol |
||
202 | 16 | * |
|
203 | * @return string |
||
204 | 16 | */ |
|
205 | protected function pointer() |
||
209 | 16 | ||
210 | 16 | public function __toString() |
|
222 | } |
||
223 |