Created
May 9, 2018 14:32
-
-
Save kobus1998/c3c990e6d9a85997175dab83dc1a186e to your computer and use it in GitHub Desktop.
Flash messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FlashMsg { | |
const SUCCESS = 'success'; | |
const WARNING = 'warning'; | |
const ERROR = 'error'; | |
/** | |
* Static msgs holder | |
* @var array | |
*/ | |
private static $msgs = [ | |
'success' => [], | |
'warning' => [], | |
'error' => [] | |
]; | |
/** | |
* Session save place | |
* @var string | |
*/ | |
private static $savePlace = 'flash'; | |
/** | |
* Set save place | |
* @param string saveplace | |
* @return void | |
*/ | |
public static function setSavePlace($savePlace = 'flash') | |
{ | |
self::$savePlace = $savePlace; | |
} | |
/** | |
* Set msgs into session | |
* @return void | |
*/ | |
public static function set() | |
{ | |
$_SESSION[self::$savePlace] = self::$msgs; | |
} | |
/** | |
* Save into object | |
* @param string const of object | |
* @param mixed anything you want to save | |
* @return void | |
*/ | |
public static function save($type = 'success', $msg) | |
{ | |
self::$msgs[$type][] = $msg; | |
} | |
/** | |
* Clear session | |
* @return void | |
*/ | |
public static function clear() | |
{ | |
self::$msgs['success'] = []; | |
self::$msgs['warning'] = []; | |
self::$msgs['error'] = []; | |
unset($_SESSION[self::$savePlace]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment