<?php
/**
 * class flashMessages
 *
 * Description for class flashMessages
 *
 * @author:
*/
namespace core;

class flashMessages {
	const success = 1;
	const notice = 2;
	const error = 3;

	public static function init() {
		if(!isset($_SESSION["__flashMessages"])) {
			$_SESSION["__flashMessages"] = array();
		}
	}

	public static function add($type, $message) {
		$_SESSION["__flashMessages"][] = array("type" => $type, "message" => $message);
	}

	public static function success($message) {
		return self::add(self::success, $message);
	}

	public static function notice($message) {
		return self::add(self::notice, $message);
	}

	public static function error($message) {
		return self::add(self::error, $message);
	}

	public static function show() {
		$messages = $_SESSION["__flashMessages"];
		self::clear();

		return $messages;
	}

	private static function clear() {
		$_SESSION["__flashMessages"] = array();
	} 
}
?>