1 | <?php |
||
7 | class Notifier |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Added notifications |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $notifications = []; |
||
16 | |||
17 | /** |
||
18 | * Added notifications |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $options = []; |
||
23 | |||
24 | /** |
||
25 | * Illuminate Session |
||
26 | * |
||
27 | * @var \Illuminate\Session\SessionManager |
||
28 | */ |
||
29 | protected $session; |
||
30 | |||
31 | /** |
||
32 | * Constructor |
||
33 | * |
||
34 | * @param \Illuminate\Session\SessionManager $session |
||
35 | * |
||
36 | * @internal param \Illuminate\Session\SessionManager $session |
||
37 | */ |
||
38 | public function __construct(SessionManager $session) |
||
42 | |||
43 | /** |
||
44 | * Render all the notifications' script to insert into script tag |
||
45 | * |
||
46 | * @return string |
||
47 | * |
||
48 | */ |
||
49 | public function render() : string |
||
65 | |||
66 | /** |
||
67 | * Render the script of given notification to insert into script tag |
||
68 | * |
||
69 | * @param $notification |
||
70 | * @return string |
||
71 | */ |
||
72 | public function renderNotification($notification): string |
||
90 | |||
91 | /** |
||
92 | * Add a notification |
||
93 | * |
||
94 | * @param string $type Could be error, info, success, or warning. |
||
95 | * @param string $message The notification's message |
||
96 | * @param string $title The notification's title |
||
97 | * @param array $options |
||
98 | * @param bool $onlyNextRequest if true(default), se the notification in session only for the next request |
||
99 | * |
||
100 | */ |
||
101 | public function add($type, $message, $title = null, array $options = [], bool $onlyNextRequest=true) |
||
120 | |||
121 | /** |
||
122 | * Shortcut for adding an info notification |
||
123 | * |
||
124 | * @param string $message The notification's message |
||
125 | * @param string $title The notification's title |
||
126 | * @param array $options |
||
127 | */ |
||
128 | public function info($message, $title = null, array $options = []) |
||
132 | |||
133 | /** |
||
134 | * Shortcut for adding an error notification |
||
135 | * |
||
136 | * @param string $message The notification's message |
||
137 | * @param string $title The notification's title |
||
138 | * @param array $options |
||
139 | */ |
||
140 | public function error($message, $title = null, array $options = []) |
||
144 | |||
145 | /** |
||
146 | * Shortcut for adding a warning notification |
||
147 | * |
||
148 | * @param string $message The notification's message |
||
149 | * @param string $title The notification's title |
||
150 | * @param array $options |
||
151 | */ |
||
152 | public function warning($message, $title = null, array $options = []) |
||
156 | |||
157 | /** |
||
158 | * Shortcut for adding a success notification |
||
159 | * |
||
160 | * @param string $message The notification's message |
||
161 | * @param string $title The notification's title |
||
162 | * @param array $options |
||
163 | */ |
||
164 | public function success($message, $title = null, array $options = []) |
||
168 | |||
169 | /** |
||
170 | * Clear all notifications |
||
171 | * @param bool $withSession if true (default) clean notifications in session too. |
||
172 | */ |
||
173 | public function clear(bool $withSession = true) |
||
181 | } |
||
182 |