2004-10-31 19:49:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @file infiniteiterator.inc
|
|
|
|
* @ingroup SPL
|
|
|
|
* @brief class InfiniteIterator
|
|
|
|
* @author Marcus Boerger
|
2005-02-08 19:10:06 +00:00
|
|
|
* @date 2003 - 2005
|
2004-10-31 19:49:18 +00:00
|
|
|
*
|
|
|
|
* SPL - Standard PHP Library
|
|
|
|
*/
|
|
|
|
|
2004-10-31 19:51:34 +00:00
|
|
|
/** @ingroup SPL
|
2004-10-31 19:49:18 +00:00
|
|
|
* @brief An infinite Iterator
|
|
|
|
* @author Marcus Boerger
|
|
|
|
* @version 1.1
|
2005-02-17 00:24:57 +00:00
|
|
|
* @since PHP 5.1
|
2004-10-31 19:49:18 +00:00
|
|
|
*
|
|
|
|
* This Iterator takes another Iterator and infinitvely iterates it by
|
|
|
|
* rewinding it when its end is reached.
|
|
|
|
*
|
|
|
|
* \note Even an InfiniteIterator stops if its inner Iterator is empty.
|
|
|
|
*
|
|
|
|
\verbatim
|
|
|
|
$it = new ArrayIterator(array(1,2,3));
|
|
|
|
$infinite = new InfiniteIterator($it);
|
|
|
|
$limit = new LimitIterator($infinite, 0, 5);
|
|
|
|
foreach($limit as $val=>$key)
|
|
|
|
{
|
|
|
|
echo "$val=>$key\n";
|
|
|
|
}
|
|
|
|
\endverbatim
|
|
|
|
*/
|
|
|
|
class InfiniteIterator extends IteratorIterator
|
|
|
|
{
|
|
|
|
/** Move the inner Iterator forward to its next element or rewind it.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function next()
|
|
|
|
{
|
|
|
|
$this->getInnerIterator()->next();
|
|
|
|
if (!$this->getInnerIterator()->valid())
|
|
|
|
{
|
|
|
|
$this->getInnerIterator()->rewind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|