1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Helpers\View; |
4
|
|
|
|
5
|
|
|
class Messages extends AbstractHelper |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
static $_cssClass = array( |
|
|
|
|
9
|
|
|
'warning' => 'alert alert-warning', |
10
|
|
|
'error' => 'alert alert-danger', |
11
|
|
|
'success' => 'alert alert-success', |
12
|
|
|
'info' => 'alert alert-info', |
13
|
|
|
); |
14
|
|
|
|
15
|
1 |
|
public static function warning($items = array(), $wrap = true) |
16
|
|
|
{ |
17
|
1 |
|
return self::render($items, 'warning', $wrap); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
1 |
|
public static function info($items = array(), $wrap = true) |
21
|
|
|
{ |
22
|
1 |
|
return self::render($items, 'info', $wrap); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public static function success($items = array(), $wrap = true) |
26
|
|
|
{ |
27
|
|
|
return self::render($items, 'success', $wrap); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public static function error($items = array(), $wrap = true) |
31
|
|
|
{ |
32
|
|
|
return self::render($items, 'error', $wrap); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
public static function render($items = array(), $type = false, $wrap = true) |
36
|
|
|
{ |
37
|
2 |
|
$return = ''; |
38
|
|
|
|
39
|
2 |
|
$items = (array)$items; |
40
|
|
|
|
41
|
2 |
|
if (count($items)) { |
42
|
2 |
|
if ($wrap) { |
43
|
2 |
|
$return .= '<div class="' . ($type ? self::$_cssClass[$type] : '') . '">'; |
44
|
2 |
|
if (count($items) > 1) { |
45
|
|
|
$return .= "<ul>"; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
2 |
View Code Duplication |
foreach ($items as $item) { |
|
|
|
|
50
|
2 |
|
$return .= is_array($item) ? self::render($item, $type, false) : (count($items) > 1 ? "<li>$item</li>" : $item); |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
if ($wrap) { |
54
|
2 |
|
if (count($items) > 1) { |
55
|
|
|
$return .= "</ul>"; |
56
|
|
|
} |
57
|
2 |
|
$return .= "</div>"; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
return $return; |
62
|
|
|
} |
63
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.