<?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;

	/**
	 * (non-PHPdoc)
	 * @see \ModulesAbstract\PluginReports\Report\Model\Gatherer\GathererAbstract::getRequiredFilters()
	 */
	public function getRequiredFilters()
	{
		return [];
	}

	/**
	 * (non-PHPdoc)
	 * @see \ModulesAbstract\PluginReports\Report\Model\Gatherer\GathererAbstract::getAcceptedFilters()
	 */
	public function getAcceptedFilters()
	{
		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;
	}
}
