1 | <?php |
||
33 | class Messenger |
||
34 | { |
||
35 | /** |
||
36 | * Default message levels |
||
37 | */ |
||
38 | const LVL_SUCCESS = 'success'; |
||
39 | const LVL_INFO = 'info'; |
||
40 | const LVL_WARNING = 'warning'; |
||
41 | |||
42 | /** |
||
43 | * Session Segment |
||
44 | * |
||
45 | * @var Segment |
||
46 | * |
||
47 | * @access protected |
||
48 | */ |
||
49 | protected $segment; |
||
50 | |||
51 | /** |
||
52 | * Create a flash messenger |
||
53 | * |
||
54 | * @param Segment $segment session storage |
||
55 | * |
||
56 | * @access public |
||
57 | */ |
||
58 | 7 | public function __construct(Segment $segment) |
|
62 | |||
63 | /** |
||
64 | * Add a message |
||
65 | * |
||
66 | * @param string $message Message text |
||
67 | * @param string $level Message level |
||
68 | * |
||
69 | * @return $this |
||
70 | * |
||
71 | * @access public |
||
72 | */ |
||
73 | 5 | public function add($message, $level = self::LVL_INFO) |
|
84 | |||
85 | /** |
||
86 | * Get current messages |
||
87 | * |
||
88 | * @return array |
||
89 | * |
||
90 | * @access public |
||
91 | */ |
||
92 | 1 | public function getMessages() |
|
96 | |||
97 | /** |
||
98 | * Set a success message |
||
99 | * |
||
100 | * @param string $message Message text |
||
101 | * |
||
102 | * @return $this |
||
103 | * |
||
104 | * @access public |
||
105 | */ |
||
106 | 1 | public function success($message) |
|
110 | |||
111 | /** |
||
112 | * Set an info message |
||
113 | * |
||
114 | * @param string $message Message text |
||
115 | * |
||
116 | * @return $this |
||
117 | * |
||
118 | * @access public |
||
119 | */ |
||
120 | 1 | public function info($message) |
|
124 | |||
125 | /** |
||
126 | * Set a warning message |
||
127 | * |
||
128 | * @param string $message Message text |
||
129 | * |
||
130 | * @return $this |
||
131 | * |
||
132 | * @access public |
||
133 | */ |
||
134 | 1 | public function warning($message) |
|
138 | } |
||
139 |