|
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\Alert; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Library\Core\Argument\Helper\ArrayHelper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Alert factory. |
|
18
|
|
|
* |
|
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
20
|
|
|
* @package WBW\Bundle\BootstrapBundle\Alert |
|
21
|
|
|
*/ |
|
22
|
|
|
class AlertFactory { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Creates a new danger alert. |
|
26
|
|
|
* |
|
27
|
|
|
* @return AlertInterface Returns the danger alert. |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function newDangerAlert(): AlertInterface { |
|
30
|
|
|
return new DangerAlert(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Creates a new default alert. |
|
35
|
|
|
* |
|
36
|
|
|
* @return AlertInterface Returns the default alert. |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function newDarkAlert(): AlertInterface { |
|
39
|
|
|
return new DarkAlert(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Creates a new info alert. |
|
44
|
|
|
* |
|
45
|
|
|
* @return AlertInterface Returns the info alert. |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function newInfoAlert(): AlertInterface { |
|
48
|
|
|
return new InfoAlert(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Creates a new light alert. |
|
53
|
|
|
* |
|
54
|
|
|
* @return AlertInterface Returns the light alert. |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function newLightAlert(): AlertInterface { |
|
57
|
|
|
return new LightAlert(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Creates a new primary alert. |
|
62
|
|
|
* |
|
63
|
|
|
* @return AlertInterface Returns the primary alert. |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function newPrimaryAlert(): AlertInterface { |
|
66
|
|
|
return new PrimaryAlert(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Creates a new secondary alert. |
|
71
|
|
|
* |
|
72
|
|
|
* @return AlertInterface Returns the secondary alert. |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function newSecondaryAlert(): AlertInterface { |
|
75
|
|
|
return new SecondaryAlert(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Creates a new success alert. |
|
80
|
|
|
* |
|
81
|
|
|
* @return AlertInterface Returns the success alert. |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function newSuccessAlert(): AlertInterface { |
|
84
|
|
|
return new SuccessAlert(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Creates a new warning alert. |
|
89
|
|
|
* |
|
90
|
|
|
* @return AlertInterface Returns the warning alert. |
|
91
|
|
|
*/ |
|
92
|
|
|
public static function newWarningAlert(): AlertInterface { |
|
93
|
|
|
return new WarningAlert(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Parses an alert. |
|
98
|
|
|
* |
|
99
|
|
|
* @param AlertInterface $alert The alert. |
|
100
|
|
|
* @param array $args The arguments. |
|
101
|
|
|
* @return AlertInterface Returns the alert. |
|
102
|
|
|
*/ |
|
103
|
|
|
protected static function parseAlert(AlertInterface $alert, array $args): AlertInterface { |
|
104
|
|
|
|
|
105
|
|
|
$alert->setContent(ArrayHelper::get($args, "content")); |
|
106
|
|
|
$alert->setDismissible(ArrayHelper::get($args, "dismissible", false)); |
|
107
|
|
|
|
|
108
|
|
|
return $alert; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Parse a danger alert. |
|
113
|
|
|
* |
|
114
|
|
|
* @param array $args The arguments. |
|
115
|
|
|
* @return AlertInterface Returns the danger alert. |
|
116
|
|
|
*/ |
|
117
|
|
|
public static function parseDangerAlert(array $args): AlertInterface { |
|
118
|
|
|
return static::parseAlert(static::newDangerAlert(), $args); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Parse a dark alert. |
|
123
|
|
|
* |
|
124
|
|
|
* @param array $args The arguments. |
|
125
|
|
|
* @return AlertInterface Returns the dark alert. |
|
126
|
|
|
*/ |
|
127
|
|
|
public static function parseDarkAlert(array $args): AlertInterface { |
|
128
|
|
|
return static::parseAlert(static::newDarkAlert(), $args); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Parse a info alert. |
|
133
|
|
|
* |
|
134
|
|
|
* @param array $args The arguments. |
|
135
|
|
|
* @return AlertInterface Returns the info alert. |
|
136
|
|
|
*/ |
|
137
|
|
|
public static function parseInfoAlert(array $args): AlertInterface { |
|
138
|
|
|
return static::parseAlert(static::newInfoAlert(), $args); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Parse a light alert. |
|
143
|
|
|
* |
|
144
|
|
|
* @param array $args The arguments. |
|
145
|
|
|
* @return AlertInterface Returns the light alert. |
|
146
|
|
|
*/ |
|
147
|
|
|
public static function parseLightAlert(array $args): AlertInterface { |
|
148
|
|
|
return static::parseAlert(static::newLightAlert(), $args); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Parse a primary alert. |
|
153
|
|
|
* |
|
154
|
|
|
* @param array $args The arguments. |
|
155
|
|
|
* @return AlertInterface Returns the primary alert. |
|
156
|
|
|
*/ |
|
157
|
|
|
public static function parsePrimaryAlert(array $args): AlertInterface { |
|
158
|
|
|
return static::parseAlert(static::newPrimaryAlert(), $args); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Parse a secondary alert. |
|
163
|
|
|
* |
|
164
|
|
|
* @param array $args The arguments. |
|
165
|
|
|
* @return AlertInterface Returns the secondary alert. |
|
166
|
|
|
*/ |
|
167
|
|
|
public static function parseSecondaryAlert(array $args): AlertInterface { |
|
168
|
|
|
return static::parseAlert(static::newSecondaryAlert(), $args); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Parse a success alert. |
|
173
|
|
|
* |
|
174
|
|
|
* @param array $args The arguments. |
|
175
|
|
|
* @return AlertInterface Returns the success alert. |
|
176
|
|
|
*/ |
|
177
|
|
|
public static function parseSuccessAlert(array $args): AlertInterface { |
|
178
|
|
|
return static::parseAlert(static::newSuccessAlert(), $args); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Parse a warning alert. |
|
183
|
|
|
* |
|
184
|
|
|
* @param array $args The arguments. |
|
185
|
|
|
* @return AlertInterface Returns the warning alert. |
|
186
|
|
|
*/ |
|
187
|
|
|
public static function parseWarningAlert(array $args): AlertInterface { |
|
188
|
|
|
return static::parseAlert(static::newWarningAlert(), $args); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|