1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the bootstrap-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\BootstrapBundle\Button; |
13
|
|
|
|
14
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Button factory. |
18
|
|
|
* |
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
20
|
|
|
* @package WBW\Bundle\BootstrapBundle\Button |
21
|
|
|
*/ |
22
|
|
|
class ButtonFactory { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Creates a new danger button. |
26
|
|
|
* |
27
|
|
|
* @return ButtonInterface Returns the danger button. |
28
|
|
|
*/ |
29
|
|
|
public static function newDangerButton() { |
30
|
|
|
return new DangerButton(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Creates a new default button. |
35
|
|
|
* |
36
|
|
|
* @return ButtonInterface Returns the default button. |
37
|
|
|
*/ |
38
|
|
|
public static function newDefaultButton() { |
39
|
|
|
return new DefaultButton(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Creates a new info button. |
44
|
|
|
* |
45
|
|
|
* @return ButtonInterface Returns the info button. |
46
|
|
|
*/ |
47
|
|
|
public static function newInfoButton() { |
48
|
|
|
return new InfoButton(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Creates a new primary button. |
53
|
|
|
* |
54
|
|
|
* @return ButtonInterface Returns the primary button. |
55
|
|
|
*/ |
56
|
|
|
public static function newPrimaryButton() { |
57
|
|
|
return new PrimaryButton(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Creates a new success button. |
62
|
|
|
* |
63
|
|
|
* @return ButtonInterface Returns the success button. |
64
|
|
|
*/ |
65
|
|
|
public static function newSuccessButton() { |
66
|
|
|
return new SuccessButton(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Creates a new warning button. |
71
|
|
|
* |
72
|
|
|
* @return ButtonInterface Returns the warning button. |
73
|
|
|
*/ |
74
|
|
|
public static function newWarningButton() { |
75
|
|
|
return new WarningButton(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Parse a danger button. |
80
|
|
|
* |
81
|
|
|
* @param array $args The arguments. |
82
|
|
|
* @return ButtonInterface Returns the danger button. |
83
|
|
|
*/ |
84
|
|
|
public static function parseDangerButton(array $args) { |
85
|
|
|
|
86
|
|
|
// Initialize the button. |
87
|
|
|
$button = static::newDangerButton(); |
88
|
|
|
|
89
|
|
|
$button->setActive(ArrayHelper::get($args, "active", false)); |
90
|
|
|
$button->setBlock(ArrayHelper::get($args, "block", false)); |
91
|
|
|
$button->setContent(ArrayHelper::get($args, "content")); |
92
|
|
|
$button->setDisabled(ArrayHelper::get($args, "disabled", false)); |
93
|
|
|
$button->setSize(ArrayHelper::get($args, "size")); |
94
|
|
|
$button->setTitle(ArrayHelper::get($args, "title")); |
95
|
|
|
|
96
|
|
|
// Return the button. |
97
|
|
|
return $button; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Parse a default button. |
102
|
|
|
* |
103
|
|
|
* @param array $args The arguments. |
104
|
|
|
* @return ButtonInterface Returns the default button. |
105
|
|
|
*/ |
106
|
|
|
public static function parseDefaultButton(array $args) { |
107
|
|
|
|
108
|
|
|
// Initialize the button. |
109
|
|
|
$button = static::newDefaultButton(); |
110
|
|
|
|
111
|
|
|
$button->setActive(ArrayHelper::get($args, "active", false)); |
112
|
|
|
$button->setBlock(ArrayHelper::get($args, "block", false)); |
113
|
|
|
$button->setContent(ArrayHelper::get($args, "content")); |
114
|
|
|
$button->setDisabled(ArrayHelper::get($args, "disabled", false)); |
115
|
|
|
$button->setSize(ArrayHelper::get($args, "size")); |
116
|
|
|
$button->setTitle(ArrayHelper::get($args, "title")); |
117
|
|
|
|
118
|
|
|
// Return the button. |
119
|
|
|
return $button; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Parse a info button. |
124
|
|
|
* |
125
|
|
|
* @param array $args The arguments. |
126
|
|
|
* @return ButtonInterface Returns the info button. |
127
|
|
|
*/ |
128
|
|
|
public static function parseInfoButton(array $args) { |
129
|
|
|
|
130
|
|
|
// Initialize the button. |
131
|
|
|
$button = static::newInfoButton(); |
132
|
|
|
|
133
|
|
|
$button->setActive(ArrayHelper::get($args, "active", false)); |
134
|
|
|
$button->setBlock(ArrayHelper::get($args, "block", false)); |
135
|
|
|
$button->setContent(ArrayHelper::get($args, "content")); |
136
|
|
|
$button->setDisabled(ArrayHelper::get($args, "disabled", false)); |
137
|
|
|
$button->setSize(ArrayHelper::get($args, "size")); |
138
|
|
|
$button->setTitle(ArrayHelper::get($args, "title")); |
139
|
|
|
|
140
|
|
|
// Return the button. |
141
|
|
|
return $button; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Parse a primary button. |
146
|
|
|
* |
147
|
|
|
* @param array $args The arguments. |
148
|
|
|
* @return ButtonInterface Returns the primary button. |
149
|
|
|
*/ |
150
|
|
|
public static function parsePrimaryButton(array $args) { |
151
|
|
|
|
152
|
|
|
// Initialize the button. |
153
|
|
|
$button = static::newPrimaryButton(); |
154
|
|
|
|
155
|
|
|
$button->setActive(ArrayHelper::get($args, "active", false)); |
156
|
|
|
$button->setBlock(ArrayHelper::get($args, "block", false)); |
157
|
|
|
$button->setContent(ArrayHelper::get($args, "content")); |
158
|
|
|
$button->setDisabled(ArrayHelper::get($args, "disabled", false)); |
159
|
|
|
$button->setSize(ArrayHelper::get($args, "size")); |
160
|
|
|
$button->setTitle(ArrayHelper::get($args, "title")); |
161
|
|
|
|
162
|
|
|
// Return the button. |
163
|
|
|
return $button; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Parse a success button. |
168
|
|
|
* |
169
|
|
|
* @param array $args The arguments. |
170
|
|
|
* @return ButtonInterface Returns the success button. |
171
|
|
|
*/ |
172
|
|
|
public static function parseSuccessButton(array $args) { |
173
|
|
|
|
174
|
|
|
// Initialize the button. |
175
|
|
|
$button = static::newSuccessButton(); |
176
|
|
|
|
177
|
|
|
$button->setActive(ArrayHelper::get($args, "active", false)); |
178
|
|
|
$button->setBlock(ArrayHelper::get($args, "block", false)); |
179
|
|
|
$button->setContent(ArrayHelper::get($args, "content")); |
180
|
|
|
$button->setDisabled(ArrayHelper::get($args, "disabled", false)); |
181
|
|
|
$button->setSize(ArrayHelper::get($args, "size")); |
182
|
|
|
$button->setTitle(ArrayHelper::get($args, "title")); |
183
|
|
|
|
184
|
|
|
// Return the button. |
185
|
|
|
return $button; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Parse a warning button. |
190
|
|
|
* |
191
|
|
|
* @param array $args The arguments. |
192
|
|
|
* @return ButtonInterface Returns the warning button. |
193
|
|
|
*/ |
194
|
|
|
public static function parseWarningButton(array $args) { |
195
|
|
|
|
196
|
|
|
// Initialize the button. |
197
|
|
|
$button = static::newWarningButton(); |
198
|
|
|
|
199
|
|
|
$button->setActive(ArrayHelper::get($args, "active", false)); |
200
|
|
|
$button->setBlock(ArrayHelper::get($args, "block", false)); |
201
|
|
|
$button->setContent(ArrayHelper::get($args, "content")); |
202
|
|
|
$button->setDisabled(ArrayHelper::get($args, "disabled", false)); |
203
|
|
|
$button->setSize(ArrayHelper::get($args, "size")); |
204
|
|
|
$button->setTitle(ArrayHelper::get($args, "title")); |
205
|
|
|
|
206
|
|
|
// Return the button. |
207
|
|
|
return $button; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|