forked from patricktalmadge/bootstrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert.php
127 lines (113 loc) · 3.21 KB
/
alert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php namespace Bootstrapper;
use \HTML;
/**
* Alert for creating Twitter Bootstrap style alerts.
*
* @package Bundles
* @subpackage Twitter
* @author Patrick Talmadge - Follow @patricktalmadge
*
* @see http://twitter.github.com/bootstrap/
*/
class Alert
{
// Alert styles
const SUCCESS = 'alert-success';
const INFO = 'alert-info';
const WARNING = 'alert-warning';
const ERROR = 'alert-error';
const DANGER = 'alert-danger';
/**
* Create a new Alert.
*
* @param string $type
* @param string $message
* @param bool $enable_close
* @param array $attributes
* @return string Alert HTML
*/
protected static function show($type, $message, $enable_close = true, $attributes = array())
{
$attributes = Helpers::add_class($attributes, 'alert '.$type);
$html = '<div'.HTML::attributes($attributes).'>';
if($enable_close)
$html .= '<a class="close" data-dismiss="alert" href="#">×</a>';
$html .= $message.'</div>';
return $html;
}
/**
* Create a new Success Alert.
*
* @param string $message
* @param bool $enable_close
* @param array $attributes
* @return string Alert HTML
*/
public static function success($message, $enable_close = true, $attributes = array())
{
return static::show(Alert::SUCCESS, $message, $enable_close, $attributes);
}
/**
* Create a new Info Alert.
*
* @param string $message
* @param bool $enable_close
* @param array $attributes
* @return string Alert HTML
*/
public static function info($message, $enable_close = true, $attributes = array())
{
return static::show(Alert::INFO, $message, $enable_close, $attributes);
}
/**
* Create a new Warning Alert.
*
* @param string $message
* @param bool $enable_close
* @param array $attributes
* @return string Alert HTML
*/
public static function warning($message, $enable_close = true, $attributes = array())
{
return static::show(Alert::WARNING, $message, $enable_close, $attributes);
}
/**
* Create a new Error Alert.
*
* @param string $message
* @param bool $enable_close
* @param array $attributes
* @return string Alert HTML
*/
public static function error($message, $enable_close = true, $attributes = array())
{
return static::show(Alert::ERROR, $message, $enable_close, $attributes);
}
/**
* Create a new Danger Alert.
*
* @param string $message
* @param bool $enable_close
* @param array $attributes
* @return string Alert HTML
*/
public static function danger($message, $enable_close = true, $attributes = array())
{
return static::show(Alert::DANGER, $message, $enable_close, $attributes);
}
/**
* Create a new custom Alert.
* This assumes you have created the appropriate css class for the alert type.
*
* @param string $type
* @param string $message
* @param bool $enable_close
* @param array $attributes
* @return string Alert HTML
*/
public static function custom($type, $message, $enable_close = true, $attributes = array())
{
$type = 'alert-'.(string)$type;
return static::show($type, $message, $enable_close, $attributes);
}
}