<?php
namespace ModulesAbstract\PluginReports\Report\Model\Iterator;

/**
 * Iterate over an input iterator/array
 * @author Lucian Sirbu
 *
 */
class ArrayIterator extends \ModulesAbstract\PluginReports\Report\Model\Gatherer\GathererAbstract
{
	/**
	 * The source 
	 * @var \Iterator
	 */
	protected $source = null;

	public function getRequiredFilters()
	{
		return [];
	}

	/**
	 * {@inheritDoc}
	 * @see \ModulesAbstract\PluginReports\Report\Model\Gatherer\GathererAbstract::objectInitialize()
	 */
	protected function objectInitialize()
	{
	}

	/**
	 * (non-PHPdoc)
	 * @see \ModulesAbstract\PluginReports\Report\Model\Gatherer\GathererAbstract::objectDestroy()
	 */
	protected function objectDestroy()
	{
		$this->source = null;
	}

	/**
	 * Set the source iterator
	 * @param \ModulesAbstract\PluginReports\Report\Model\Gatherer\GathererAbstract $gatherer
	 * @return \ModulesAbstract\PluginReports\Report\Model\Iterator\MapResultsIterator
	 */
	public function setSource($source)
	{
		$this->source = $source;
		return $this;
	}

	/**
	 * {@inheritDoc}
	 * @see \ModulesAbstract\PluginReports\Report\Model\Gatherer\GathererAbstract::objectNext()
	 */
	protected function objectNext()
	{
		$ret = next($this->source);
		$key = key($this->source);
		if ($key!==null) {
			return null;
		}

		return $ret;
	}
}
