<commit_before><?php
/**
 * @author ueaner <<EMAIL>>
 */
namespace Soli\Session;

use Soli\Di\ContainerAwareInterface;
use Soli\Di\ContainerAwareTrait;

/**
 * 闪存消息
 */
class Flash implements ContainerAwareInterface
{
    use ContainerAwareTrait;

    protected $cssClasses = [
        'error'   => 'error',
        'notice'  => 'notice',
        'success' => 'success',
        'warning' => 'warning'
    ];

    protected $messages;

    protected $flashKey = '__flashMessages';

    /**
     * Flash constructor.
     *
     * @param array $cssClasses 消息样式
     */
    public function __construct(array $cssClasses = null)
    {
        if (is_array($cssClasses)) {
            $this->setCssClasses($cssClasses);
        }
    }

    /**
     * 设置消息样式
     *
     * @param array $cssClasses
     */
    public function setCssClasses(array $cssClasses)
    {
        $this->cssClasses = array_merge($this->cssClasses, $cssClasses);
    }

    /**
     * @return array
     */
    public function getCssClasses()
    {
        return $this->cssClasses;
    }

    public function error($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    public function notice($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    public function success($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    public function warning($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    /**
     * 处理各个类型的 flash message
     *
     * @param string $type success|error|notice|warning
     * @param string $message
     */
    public function message($type, $message)
    {
        if (isset($this->cssClasses[$type])) {
            $session = $this->container->getShared('session');
            $html = '<div class="%s">%s</div>';
            $this->messages[] = sprintf($html, $this->cssClasses[$type], $message);
            $session->set($this->flashKey, $this->messages);
        }
    }

    /**
     * 输出 flash messages
     *
     * @param bool $remove 输出后是否删除 flash messages<commit_msg>调整函数顺序<commit_after><?php
/**
 * @author ueaner <<EMAIL>>
 */
namespace Soli\Session;

use Soli\Di\ContainerAwareInterface;
use Soli\Di\ContainerAwareTrait;

/**
 * 闪存消息
 */
class Flash implements ContainerAwareInterface
{
    use ContainerAwareTrait;

    protected $cssClasses = [
        'error'   => 'error',
        'notice'  => 'notice',
        'warning' => 'warning',
        'success' => 'success'
    ];

    protected $messages;

    protected $flashKey = '__flashMessages';

    /**
     * Flash constructor.
     *
     * @param array $cssClasses 消息样式
     */
    public function __construct(array $cssClasses = null)
    {
        if (is_array($cssClasses)) {
            $this->setCssClasses($cssClasses);
        }
    }

    /**
     * 设置消息样式
     *
     * @param array $cssClasses
     */
    public function setCssClasses(array $cssClasses)
    {
        $this->cssClasses = array_merge($this->cssClasses, $cssClasses);
    }

    /**
     * @return array
     */
    public function getCssClasses()
    {
        return $this->cssClasses;
    }

    public function error($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    public function notice($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    public function warning($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    public function success($message)
    {
        $this->message(__FUNCTION__, $message);
    }

    /**
     * 处理各个类型的 flash message
     *
     * @param string $type success|error|notice|warning
     * @param string $message
     */
    public function message($type, $message)
    {
        if (isset($this->cssClasses[$type])) {
            $session = $this->container->getShared('session');
            $html = '<div class="%s">%s</div>';
            $this->messages[] = sprintf($html, $this->cssClasses[$type], $message);
            $session->set($this->flashKey, $this->messages);
        }
    }

    /**
     * 输出 flash messages
     *
     * @param bool $remove 输出后是否删除 flash messages
{'fraction_non_alphanumeric': 0.14462509099733076, 'fraction_numerical': 0.0, 'mean_word_length': 2.232941176470588, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 51, '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': '2103305', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1285, 'n_words': 239}