-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlash.php
41 lines (37 loc) · 1.38 KB
/
Flash.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
<?php
namespace App;
/* Flash Class */
class Flash {
/* Flash CONSTANTS: Message Types */
const SUCCESS = 'success';
const INFO = 'info';
const WARNING = 'warning';
/* METHOD: addMessage
* @param string : $message to display and the type, which defaults to 'success'; therefore, this argument is optional
* @return void : Render the $message in a View
*/
public static function addMessage($message,$type = 'success') {
/* Ensure that an array exists in the SESSION for the message, so that it can be used to render a flash notification */
if (! isset($_SESSION['flash_notifications'])) {
$_SESSION['flash_notifications'] = [];
}
/* Append the message to an array */
$_SESSION['flash_notifications'][] = [
'body' => $message,
'type' => $type
];
}
/* METHOD: getMessages
* @param void :
* @return mixed : Returns an array with all the messages, or null
*/
public static function getMessages() {
if (isset($_SESSION['flash_notifications'])) {
/* Store the SESSION flash notifications into a variable, unset the SESSION, and then return just the variable */
$messages = $_SESSION['flash_notifications'];
unset($_SESSION['flash_notifications']);
return $messages;
}
}
}
?>