<?php
namespace Crehler\FastNavigation\Service;
class NavigationIteratorService implements \Iterator
{
private $position;
/**
* @var array
*/
private $array;
public function setArray(array $array)
{
$this->array = $array;
}
public function setCurrent($position = 0)
{
$this->position = $position;
}
/**
* @return mixed|\TValue
*/
public function current()
{
return $this->array[$this->position];
}
/**
* @inheritDoc
*/
public function next()
{
++$this->position;
}
public function prev()
{
--$this->position;
}
public function key()
{
return $this->position;
}
/**
* @inheritDoc
*/
public function valid()
{
return isset($this->array[$this->position]);
}
/**
* @inheritDoc
*/
public function rewind()
{
$this->position = 0;
}
public function find($element)
{
return array_search($element, $this->array);
}
}