<?php
require_once 'CommandInterface.php';

class 
Queue
{
    private 
$_commands;
    private 
$_currentIndex;

    public function 
__construct()
    {
        
$this->_commands     = array();
        
$this->_currentIndex 0;
    }

    public function 
addCommand(CommandInterface $command)
    {
        
$this->_commands[] = $command;
    }

    public function 
run()
    {
        while (!
is_null($command $this->next())) {
            echo 
$command->execute();
        }
    }

    private function 
next()
    {
        if (
count($this->_commands) === || count($this->_commands) <= $this->_currentIndex) {
            return 
null;
        } else {
            return 
$this->_commands[$this->_currentIndex++];
        }
    }
}