php-src/ext/spl/internal/iteratoriterator.inc

96 lines
1.8 KiB
PHP
Raw Normal View History

2004-09-26 21:21:45 +00:00
<?php
/** @file iteratoriterator.inc
* @ingroup SPL
* @brief class IteratorIterator
* @author Marcus Boerger
2005-02-08 19:10:06 +00:00
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup SPL
* @brief Basic Iterator wrapper
2004-09-26 21:21:45 +00:00
*/
class IteratorIterator implements OuterIterator
{
/** Construct an IteratorIterator from an Iterator or an IteratorAggregate.
*
* Classes that only implement Traversable can be wrapped only after
2004-09-29 20:27:36 +00:00
* converting class IteratorIterator into c code.
2004-09-26 21:21:45 +00:00
*/
function __construct(Traversable $iterator)
{
if ($iterator instanceof IteratorAggregate)
{
$iterator = $iterator->getIterator();
}
if ($iterator instanceof Iterator)
{
$this->iterator = $iterator;
}
else
{
throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorItaerator into c code");
}
}
/** \return the inner iterator as passed to the constructor
*/
function getInnerIterator()
{
return $this->iterator;
}
2004-09-29 20:27:36 +00:00
/** \return whether the iterator is valid
2004-09-26 21:21:45 +00:00
*/
function valid()
{
return $this->iterator->valid();
}
/** \return current key
*/
function key()
{
return $this->iterator->key();
}
/** \return current value
*/
function current()
{
return $this->iterator->current();
}
/** forward to next element
*/
function next()
{
return $this->iterator->next();
}
/** rewind to the first element
*/
function rewind()
{
return $this->iterator->rewind();
}
2004-10-31 19:05:37 +00:00
/** Aggregate the inner iterator
*
* @param func Name of method to invoke
* @param params Array of parameters to pass to method
*/
function __call($func, $params)
{
return call_user_func_array(array($this->it, $func), $params);
}
2004-09-29 20:27:36 +00:00
/** The inner iterator must be private because when this class will be
2004-09-26 21:21:45 +00:00
* converted to c code it won't no longer be available.
*/
private $iterator;
}
?>