<?php
/**
 * Arquivo de declaração da classe Message.
 */
class Message
{
    /**
     * Set success message.
     *
     * @param  string $message
     */
    public static function success($message = '')
    {
        $_SESSION['success'] = $message;
    }

    /**
     * Set error message.
     *
     * @param  string $message
     */
    public static function error($message = '')
    {
        $_SESSION['errors'] = $message;
    }

    /**
     * Exists errors message.
     *
     * @return boolean
     */
    public static function hasErrors()
    {
        return isset($_SESSION['errors']) && !empty($_SESSION['errors']);
    }

    /**
     * Exists success message.
     *
     * @return boolean
     */
    public static function hasSuccess()
    {
        return isset($_SESSION['success']) && !empty($_SESSION['success']);
    }

    /**
     * Show errors message.
     */
    public static function showErrors()
    {
        if (!self::hasErrors()) {
            return false;
        }

        $msg = $_SESSION['errors'];

        unset($_SESSION['errors']);

        return $msg;
    }

    /**
     * Show success message.
     */
    public static function showSuccess()
    {
        if (!self::hasSuccess()) {
            return false;
        }

        $msg = $_SESSION['success'];

        unset($_SESSION['success']);

        return $msg;
    }
}
