<?php

namespace Plainwork\Ui;

final class FlashMessenger
{
    private $messages = [];

    public function register(string $msg): self
    {
        $this->messages[] = $msg;

        return $this;
    }

    public function getMessageById(int $id): string
    {
        return $this->messages[$id] ?? '';
    }

    public function getMessageId(string $msg): ?int
    {
        $ret = array_search($msg, $this->messages);
        if (false === $ret) {
            $ret = null;
        }

        return $ret;
    }
}
