1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpSchool\CliMenu\MenuItem; |
4
|
|
|
|
5
|
|
|
use PhpSchool\CliMenu\MenuStyle; |
6
|
|
|
use PhpSchool\CliMenu\Util\StringUtil; |
7
|
|
|
use PhpSchool\CliMenu\Style\SelectableStyle; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Michael Woodward <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class StaticItem implements MenuItemInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $text; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var SelectableStyle; |
21
|
|
|
*/ |
22
|
|
|
private $style; |
23
|
|
|
|
24
|
|
|
public function __construct(string $text) |
25
|
|
|
{ |
26
|
|
|
$this->text = $text; |
27
|
|
|
|
28
|
|
|
$this->style = new SelectableStyle(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The output text for the item |
33
|
|
|
*/ |
34
|
|
|
public function getRows(MenuStyle $style, bool $selected = false) : array |
35
|
|
|
{ |
36
|
|
|
return explode("\n", StringUtil::wordwrap($this->text, $style->getContentWidth())); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Can the item be selected |
41
|
|
|
*/ |
42
|
|
|
public function canSelect() : bool |
43
|
|
|
{ |
44
|
|
|
return false; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Execute the items callable if required |
49
|
|
|
*/ |
50
|
|
|
public function getSelectAction() : ?callable |
51
|
|
|
{ |
52
|
|
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getStyle() : SelectableStyle |
56
|
|
|
{ |
57
|
|
|
return $this->style; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function setStyle(SelectableStyle $style) : self |
61
|
|
|
{ |
62
|
|
|
$this->style = $style; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return the raw string of text |
69
|
|
|
*/ |
70
|
|
|
public function getText() : string |
71
|
|
|
{ |
72
|
|
|
return $this->text; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set the raw string of text |
77
|
|
|
*/ |
78
|
|
|
public function setText(string $text) : void |
79
|
|
|
{ |
80
|
|
|
$this->text = $text; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Whether or not the menu item is showing the menustyle extra value |
85
|
|
|
*/ |
86
|
|
|
public function showsItemExtra() : bool |
87
|
|
|
{ |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Enable showing item extra |
93
|
|
|
*/ |
94
|
|
|
public function showItemExtra() : void |
95
|
|
|
{ |
96
|
|
|
//noop |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Disable showing item extra |
101
|
|
|
*/ |
102
|
|
|
public function hideItemExtra() : void |
103
|
|
|
{ |
104
|
|
|
//noop |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|