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