<commit_before><?php

namespace marius321967\Messages;

use Illuminate\Session\SessionManager;

class MessageHandler {

    protected $messages = [];

    protected $flash_messages = [];

    /**
     * @var SessionManager
     */
    protected $sessionManager;


    public function __construct() {
        $this->sessionManager = app(SessionManager::class);

        if ($this->sessionManager->has('flash_messages'))
            $this->messages = $this->sessionManager->get('flash_messages');
    }

    public function getAll() {
        return $this->messages;
    }

    public function getFlash() {
        return $this->flash_messages;
    }

    public function add($message, $type = 'info') {
        $this->messages[] = [
            'message' => $message,
            'type' => $type,
        ];
    }

    public function flash($message, $type = 'info') {
        $this->flash_messages[] = [
            'message' => $message,
            'type' => $type,
        ];
    }

}<commit_msg>Flashed messages will be lazily loaded<commit_after><?php

namespace marius321967\Messages;

use Illuminate\Session\SessionManager;

class MessageHandler {

    protected $messages;

    protected $flash_messages = [];

    /**
     * @var SessionManager
     */
    protected $sessionManager;


    public function __construct() {
        $this->sessionManager = app(SessionManager::class);

        if ($this->sessionManager->has('flash_messages'))
            $this->messages = $this->sessionManager->get('flash_messages');
    }

    public function getAll() {
        if (is_null($this->messages))
            $this->loadFlashedMessages();

        return $this->messages;
    }

    public function getFlash() {
        return $this->flash_messages;
    }

    public function add($message, $type = 'info') {
        if (is_null($this->messages))
            $this->loadFlashedMessages();

        $this->messages[] = [
            'message' => $message,
            'type' => $type,
        ];
    }

    public function flash($message, $type = 'info') {
        $this->flash_messages[] = [
            'message' => $message,
            'type' => $type,
        ];
    }

    private function loadFlashedMessages() {
        $flashed = $this->sessionManager->get('flash_messages');
        $flashed = ($flashed) ?: []; // Or empty array.
        $this->messages = $flashed;
    }

}
{'fraction_non_alphanumeric': 0.1473419840937631, 'fraction_numerical': 0.0050230221850146506, 'mean_word_length': 2.296551724137931, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, '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': '774881', 'n_tokens_mistral': 689, 'n_tokens_neox': 660, 'n_words': 131}