<?php
/**
 * Arquivo de declaração da classe Session.
 */
class Session
{
    public function __construct()
    {
        if (!session_id()) {
            session_start();
        }
    }

    public static function set($index, $value)
    {
        $_SESSION[$index] = $value;
    }

    public static function get($index)
    {
        return isset($_SESSION[$index]) ? $_SESSION[$index] : false;
    }

    public static function exist($index)
    {
        return (bool) (isset($_SESSION[$index]));
    }

    public static function delete($index)
    {
        if (isset($_SESSION[$index])) {
            unset($_SESSION[$index]);
            return false;
        }
    }

    public static function destroy()
    {
        if (isset($_SESSION)) {
            foreach ($_SESSION as $key => $value) {
                static::delete($key);
            }

            session_destroy();
        }
    }

    public static function dump()
    {
        if (isset($_SESSION)) {
            echo '<pre>';
            print_r($_SESSION);
            echo '</pre>';
            return;
        }

        throw new Exception('Session is not initialized');
    }
}
