1 | <?php |
||
11 | class Message implements \IteratorAggregate |
||
12 | { |
||
13 | const MESSAGE = 'message'; |
||
14 | const ALERT = 'alert'; |
||
15 | const ERROR = 'error'; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $messages = []; |
||
21 | |||
22 | public $formats = [ |
||
23 | self::MESSAGE => '<div class="alert alert-success">%s</div>', |
||
24 | self::ALERT => '<div class="alert alert-info">%s</div>', |
||
25 | self::ERROR => '<div class="alert alert-danger">%s</div>', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @param array $data |
||
30 | */ |
||
31 | private function __construct($data = []) |
||
35 | |||
36 | /** |
||
37 | * @param array $data |
||
38 | * @return Message |
||
39 | */ |
||
40 | public static function forge($data) |
||
44 | |||
45 | /** |
||
46 | * @param string $message |
||
47 | * @param string $type |
||
48 | */ |
||
49 | public function add($message, $type = self::MESSAGE) |
||
53 | |||
54 | /** |
||
55 | * @param array $msg |
||
56 | * @return string |
||
57 | */ |
||
58 | private function show($msg) |
||
64 | |||
65 | /** |
||
66 | * show the most severe message only once. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function onlyOne() |
||
78 | |||
79 | /** |
||
80 | * @return string[] |
||
81 | */ |
||
82 | public function findMostSerious() |
||
102 | |||
103 | /** |
||
104 | * @return string |
||
105 | */ |
||
106 | public function __toString() |
||
114 | |||
115 | /** |
||
116 | * Retrieve an external iterator |
||
117 | * |
||
118 | * @return Traversable|string[] |
||
119 | */ |
||
120 | public function getIterator() |
||
126 | } |