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