1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpSchool\CliMenu\Style; |
4
|
|
|
|
5
|
|
|
class RadioStyle |
6
|
|
|
{ |
7
|
|
|
private const DEFAULT_STYLES = [ |
8
|
|
|
'checkedMarker' => '[●] ', |
9
|
|
|
'uncheckedMarker' => '[○] ', |
10
|
|
|
'itemExtra' => '✔', |
11
|
|
|
'displaysExtra' => false, |
12
|
|
|
]; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $checkedMarker; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $uncheckedMarker; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $itemExtra; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
private $displaysExtra; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
protected $custom = false; |
38
|
|
|
|
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
$this->checkedMarker = self::DEFAULT_STYLES['checkedMarker']; |
42
|
|
|
$this->uncheckedMarker = self::DEFAULT_STYLES['uncheckedMarker']; |
43
|
|
|
$this->itemExtra = self::DEFAULT_STYLES['itemExtra']; |
44
|
|
|
$this->displaysExtra = self::DEFAULT_STYLES['displaysExtra']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function hasChangedFromDefaults() : bool |
48
|
|
|
{ |
49
|
|
|
$currentValues = [ |
50
|
|
|
$this->checkedMarker, |
51
|
|
|
$this->uncheckedMarker, |
52
|
|
|
$this->itemExtra, |
53
|
|
|
$this->displaysExtra, |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
return $currentValues !== array_values(self::DEFAULT_STYLES); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getMarker(bool $selected) : string |
60
|
|
|
{ |
61
|
|
|
return $selected ? $this->checkedMarker : $this->uncheckedMarker; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getCheckedMarker() : string |
65
|
|
|
{ |
66
|
|
|
return $this->checkedMarker; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setCheckedMarker(string $marker) : self |
70
|
|
|
{ |
71
|
|
|
$this->checkedMarker = $marker; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getUncheckedMarker() : string |
77
|
|
|
{ |
78
|
|
|
return $this->uncheckedMarker; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setUncheckedMarker(string $marker) : self |
82
|
|
|
{ |
83
|
|
|
$this->uncheckedMarker = $marker; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getItemExtra() : string |
89
|
|
|
{ |
90
|
|
|
return $this->itemExtra; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setItemExtra(string $itemExtra) : self |
94
|
|
|
{ |
95
|
|
|
$this->itemExtra = $itemExtra; |
96
|
|
|
|
97
|
|
|
// if we customise item extra, it means we most likely want to display it |
98
|
|
|
$this->setDisplaysExtra(true); |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getDisplaysExtra() : bool |
104
|
|
|
{ |
105
|
|
|
return $this->displaysExtra; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function setDisplaysExtra(bool $displaysExtra) : self |
109
|
|
|
{ |
110
|
|
|
$this->displaysExtra = $displaysExtra; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|