<?php

namespace NPS\Etc;

/**
 * Trait for any object to be able to post string messages to other objects
 * @author Lukas Korinek
 */
trait TMessage
{
    /** @var array $messages */
    private $messages = [];

    /** @var int $messagePointer */
    private $messagePointer = 0;

    /**
     * @inheritdoc
     */
    public function popMessage()
    {
        if(isset($this->messages[$this->messagePointer]))
        {
            return $this->messages[$this->messagePointer++];
        }
        
        return null;
    }


    /**
     * @inheritdoc
     */
    public function logMessages()
    {
        return $this->messages;
    }

    
    /**
     * Pushes a message
     * @param string $message
     */
    private function pushMessage($message)
    {
        $this->messages[] = (string)$message;
    }
}

