1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebTheory\Saveyour\Elements; |
4
|
|
|
|
5
|
|
|
use WebTheory\Html\AbstractHtmlElement; |
6
|
|
|
|
7
|
|
|
class Option extends AbstractHtmlElement |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected $text; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $value; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $selected = false; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
protected $disabled = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
public function __construct(string $text, string $value) |
33
|
|
|
{ |
34
|
|
|
$this->text = $text; |
35
|
|
|
$this->value = $value; |
36
|
|
|
|
37
|
|
|
parent::__construct(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the value of text |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function getText(): string |
46
|
|
|
{ |
47
|
|
|
return $this->text; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the value of value |
52
|
|
|
* |
53
|
|
|
* @return mixed |
54
|
|
|
*/ |
55
|
|
|
public function getValue() |
56
|
|
|
{ |
57
|
|
|
return $this->value; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the value of selected |
62
|
|
|
* |
63
|
|
|
* @return bool |
64
|
|
|
*/ |
65
|
|
|
public function isSelected(): bool |
66
|
|
|
{ |
67
|
|
|
return $this->selected; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Set the value of selected |
72
|
|
|
* |
73
|
|
|
* @param bool $selected |
74
|
|
|
* |
75
|
|
|
* @return self |
76
|
|
|
*/ |
77
|
|
|
public function setSelected(bool $selected) |
78
|
|
|
{ |
79
|
|
|
$this->selected = $selected; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the value of disabled |
86
|
|
|
* |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isDisabled(): bool |
90
|
|
|
{ |
91
|
|
|
return $this->disabled; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set the value of disabled |
96
|
|
|
* |
97
|
|
|
* @param bool $disabled |
98
|
|
|
* |
99
|
|
|
* @return self |
100
|
|
|
*/ |
101
|
|
|
public function setDisabled(bool $disabled) |
102
|
|
|
{ |
103
|
|
|
$this->disabled = $disabled; |
104
|
|
|
|
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* |
110
|
|
|
*/ |
111
|
|
|
protected function resolveAttributes(): AbstractHtmlElement |
112
|
|
|
{ |
113
|
|
|
return parent::resolveAttributes() |
114
|
|
|
->addAttribute('value', $this->value) |
|
|
|
|
115
|
|
|
->addAttribute('selected', $this->selected) |
116
|
|
|
->addAttribute('disabled', $this->disabled); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* |
121
|
|
|
*/ |
122
|
|
|
protected function renderHtmlMarkup(): string |
123
|
|
|
{ |
124
|
|
|
return $this->tag('option', $this->text, $this->attributes); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|