<?php


namespace CMSMSExt\core;


class queue
{
  private $queue;
  
  public function __construct()
  {
    $this->queue = [];
  }
  
  public function enqueue($item)
  {
    $this->queue[] = $item;
    
    return $this;
  }
  
  public function dequeue()
  {
    if($this->isEmpty())
    {
      throw new \RuntimeException('queue is empty');
    }
    
    return \array_shift($this->queue);
  }
  
  public function peek()
  {
    if($this->isEmpty())
    {
      throw new \RuntimeException('queue is empty');
    }
    
    return \reset($this->queue);
  }
  
  public function isEmpty() : bool
  {
    return empty($this->queue);
  }
  
  public function size() : int
  {
    return \count($this->queue);
  }
  
  public function reset() : queue
  {
    $this->queue = [];
    
    return $this;
  }
}


?>