1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Alert view helper styled for Bootstrap 3. |
5
|
|
|
* |
6
|
|
|
* @author Leandro Silva <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @category LosUi |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License |
11
|
|
|
* |
12
|
|
|
* @link http://github.com/LansoWeb/LosUi |
13
|
|
|
* @link http://getbootstrap.com/components/#alerts |
14
|
|
|
*/ |
15
|
|
|
namespace LosUi\View\Helper; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Alert view helper styled for Bootstrap 3. |
19
|
|
|
* |
20
|
|
|
* @author Leandro Silva <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @category LosUi |
23
|
|
|
* |
24
|
|
|
* @license https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License |
25
|
|
|
* |
26
|
|
|
* @link http://github.com/LansoWeb/LosUi |
27
|
|
|
* @link http://getbootstrap.com/components/#alerts |
28
|
|
|
*/ |
29
|
|
|
class Alert |
30
|
|
|
{ |
31
|
|
|
protected $format = '<div class="alert %s" role="alert">%s</div>'; |
32
|
|
|
|
33
|
|
|
protected $formatDismissible = '<div class="alert alert-dismissible %s" role="alert"><button type="button" '. |
34
|
|
|
'class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span>'. |
35
|
|
|
'</button>%s</div>'; |
36
|
|
|
|
37
|
|
|
protected $isDismissible = false; |
38
|
|
|
|
39
|
|
|
public function info($alert) |
40
|
|
|
{ |
41
|
|
|
return $this->render($alert, 'alert-info'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function danger($alert) |
45
|
|
|
{ |
46
|
|
|
return $this->render($alert, 'alert-danger'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function error($alert) |
50
|
|
|
{ |
51
|
|
|
return $this->danger($alert); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function success($alert) |
55
|
|
|
{ |
56
|
|
|
return $this->render($alert, 'alert-success'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function warning($alert) |
60
|
|
|
{ |
61
|
|
|
return $this->render($alert, 'alert-warning'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function render($alert, $class = 'alert-warning') |
65
|
|
|
{ |
66
|
|
|
$class = trim($class); |
67
|
|
|
|
68
|
|
|
if ($this->isDismissible) { |
69
|
|
|
return sprintf($this->formatDismissible, $class, $alert); |
70
|
|
|
} else { |
71
|
|
|
return sprintf($this->format, $class, $alert); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setDismissible($dismissible) |
76
|
|
|
{ |
77
|
|
|
if (! is_bool($dismissible)) { |
78
|
|
|
throw new \InvalidArgumentException('Argument must be a bool value.'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$this->isDismissible = $dismissible; |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function __invoke($alert = null, $class = 'alert-warning') |
87
|
|
|
{ |
88
|
|
|
if ($alert) { |
89
|
|
|
return $this->render($alert, $class); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|