Skip to content

Instantly share code, notes, and snippets.

@beeblebrox3
Created May 9, 2013 12:40
Show Gist options
  • Save beeblebrox3/5547215 to your computer and use it in GitHub Desktop.
Save beeblebrox3/5547215 to your computer and use it in GitHub Desktop.
<?php
/*
No Controller use
Sysfeedback::success("mensagem");
Na View/Layout use
Sysfeedback::render();
Isto irá mostrar todas as mensagens disponíveis
*/
class Sysfeedback {
private static $types = array(
'success',
'error',
'info',
);
public static function render() {
foreach(self::$types as $type) {
$_type = 'sys-'.$type;
if(Session::has($_type)) {
self::html($type, Session::get($_type));
Session::forget($_type);
}
}
}
private static function addMessage($type, $message) {
$messages = (array) Session::get($type);
$messages[] = $message;
Session::put($type, $messages);
}
private static function html($class, $messages) {
echo '<div class="alert alert-'.$class.'">';
foreach($messages as $msg) {
echo $msg.'<br />';
}
echo '</div>';
}
public static function __callStatic($type, $args) {
if(!in_array($type, self::$types)) {
return false;
}
$type = 'sys-'.$type;
$message = $args[0];
self::addMessage($type, $message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment