<commit_before>
namespace Ice;

/**
 * Shows HTML notifications related to different circumstances.
 *
 * @package     Ice/Flash
 * @category    Helper
 * @author      Ice Team
 * @copyright   (c) 2014-2018 Ice Team
 * @license     http://iceframework.org/license
 */
class Flash
{

    protected session;
    protected tag;
    protected options = [
        "session_key": "_flash",
        "success": ["class": "alert alert-success"],
        "info": ["class": "alert alert-info"],
        "warning": ["class": "alert alert-warning"],
        "danger": ["class": "alert alert-danger"],
        "html": true
    ] { set };

    /**
     * Flash constructor. Fetch session and tag service from the di.
     *
     * @param array options
     */
    public function __construct(array options = [])
    {
        var di;

        let di = Di::$fetch(),
            this->session = di->get("session"),
            this->tag = di->get("tag");

        if count(options) {
            let this->options = options;
        }
    }

    /**
     * Get option value with key.
     *
     * @param string key The option key
     * @param mixed defaultValue The value to return if option key does not exist
     * @return mixed
     */
    public function getOption(string! key, var defaultValue = null)
    {
        var value;

        if fetch value, this->options[key] {
            return value;
        }
        return defaultValue;
    }

    /**
     * Display the messages.
     *
     * @param boolean remove
     * @return string
     */
    public function getMessages(boolean remove = true) -> string
    {
        var key, type, message, messages, body;

        let key = this->getOption("session_key"),
            messages = this->session->get(key),
            body = "";

        if typeof messages == "array" {
            for type, message in messages {
                let body .= this->getMessage(type, message);
            }
        }

        if remove {
            this->session->remove(key);
        }

        return body;
    }

    /**
     * Get a message formatting it with HTML.
     *
     * @param string type
     * @param mixed message
     * @return string
     */
    public function getMessage(string type, var messages) -> string
    {
        var params, body, close, message;

        let params = this->getOption(type, []),
            close = this->tag->a(["#", "×", "class": "close"]),
            body = "";

        if typeof messages != "array" {
            let messages = [messages];
        }

        for message in messages {
            if this->getOption("html") {
                let body .= this->tag->tagHtml("div", params, ["content": close . message],  ["content"], "content", true, true);
            } else {
                let body .= message . PHP_EOL;
            }
        }

        return body;
    }

    /**
     * Adds a message to the flash.
     *
     * @param string type
     * @param string message
     * @return object Flash
     */
    public function message(string type, string message)
    {
        var key, messages;

        let key = this->getOption("session_key"),
            messages = this->session->get(key, []);

        if !isset messages[type] {
            let messages[type] = [];
        }

        let messages[type][] = message;

        this->session->set(key, messages);
        
        return this;
    }

    /**
     * Add success message.
     *
     * @param string message
     * @return object Flash
     */
    public function success(string message)
    {
        this->message("success", message);
        
        return this;
    }

    /**
     * Alias of success message.
     * @return object Flash
     */
    public function ok(string message)
    {
        return this->message("success", message);
    }

    /**
     * Add info message.
     *
     * @param string message
     * @return object Flash
     */
    public function info(string message)
    {
        return this->message("info", message);
    }

    /**
     * Alias of info message.
     * @return object Flash
     */
    public function notice(string message)<commit_msg>Flash, add dismissible class<commit_after>
namespace Ice;

/**
 * Shows HTML notifications related to different circumstances.
 *
 * @package     Ice/Flash
 * @category    Helper
 * @author      <NAME>
 * @copyright   (c) 2014-2018 Ice Team
 * @license     http://iceframework.org/license
 */
class Flash
{

    protected session;
    protected tag;
    protected options = [
        "session_key": "_flash",
        "success": ["class": "alert alert-success alert-dismissible fade show"],
        "info": ["class": "alert alert-info alert-dismissible fade show"],
        "warning": ["class": "alert alert-warning alert-dismissible fade show"],
        "danger": ["class": "alert alert-danger alert-dismissible fade show"],
        "close": ["close", "×", "type": "button", "class": "close", "data-dismiss": "alert"],
        "html": true
    ] { set };

    /**
     * Flash constructor. Fetch session and tag service from the di.
     *
     * @param array options
     */
    public function __construct(array options = [])
    {
        var di;

        let di = Di::$fetch(),
            this->session = di->get("session"),
            this->tag = di->get("tag");

        if count(options) {
            let this->options = options;
        }
    }

    /**
     * Get option value with key.
     *
     * @param string key The option key
     * @param mixed defaultValue The value to return if option key does not exist
     * @return mixed
     */
    public function getOption(string! key, var defaultValue = null)
    {
        var value;

        if fetch value, this->options[key] {
            return value;
        }
        return defaultValue;
    }

    /**
     * Display the messages.
     *
     * @param boolean remove
     * @return string
     */
    public function getMessages(boolean remove = true) -> string
    {
        var key, type, message, messages, body;

        let key = this->getOption("session_key"),
            messages = this->session->get(key),
            body = "";

        if typeof messages == "array" {
            for type, message in messages {
                let body .= this->getMessage(type, message);
            }
        }

        if remove {
            this->session->remove(key);
        }

        return body;
    }

    /**
     * Get a message formatting it with HTML.
     *
     * @param string type
     * @param mixed message
     * @return string
     */
    public function getMessage(string type, var messages) -> string
    {
        var params, body, close, message;

        let params = this->getOption(type, []),
            close = this->tag->button(this->getOption("close", [])),
            body = "";

        if typeof messages != "array" {
            let messages = [messages];
        }

        for message in messages {
            if this->getOption("html") {
                let body .= this->tag->tagHtml("div", params, ["content": close . message],  ["content"], "content", true, true);
            } else {
                let body .= message . PHP_EOL;
            }
        }

        return body;
    }

    /**
     * Adds a message to the flash.
     *
     * @param string type
     * @param string message
     * @return object Flash
     */
    public function message(string type, string message)
    {
        var key, messages;

        let key = this->getOption("session_key"),
            messages = this->session->get(key, []);

        if !isset messages[type] {
            let messages[type] = [];
        }

        let messages[type][] = message;

        this->session->set(key, messages);

        return this;
    }

    /**
     * Add success message.
     *
     * @param string message
     * @return object Flash
     */
    public function success(string message)
    {
        this->message("success", message);

        return this;
    }

    /**
     * Alias of success message.
     * @return object Flash
     */
    public function ok(string message)
    {
        return this->message("success", message);
    }

    /**
     * Add info message.
     *
     * @param string message
     * @return object Flash
     */
    public function info(string message)
    {
        return this->message("info", message);
    }

    /**
     * Alias of info message.
     * @return object Flash
     */
    public function notice(string message)
{'fraction_non_alphanumeric': 0.12511737089201877, 'fraction_numerical': 0.0018779342723004694, 'mean_word_length': 1.7345956354300385, 'pattern_counts': {'":': 27, '<': 4, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6045589', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2263, 'n_words': 693}