2003-11-09 14:05:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Iterates through recursive iterators
|
|
|
|
* @author Marcus Boerger
|
|
|
|
* @version 1.0
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class RecursiveIteratorIterator implements Iterator
|
|
|
|
{
|
|
|
|
protected $ait = array();
|
|
|
|
protected $count = 0;
|
|
|
|
|
2003-11-22 20:51:15 +00:00
|
|
|
function __construct(RecursiveIterator $it)
|
|
|
|
{
|
2003-11-09 14:05:36 +00:00
|
|
|
$this->ait[0] = $it;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-22 20:51:15 +00:00
|
|
|
function rewind()
|
|
|
|
{
|
|
|
|
while ($this->count) {
|
|
|
|
unset($this->ait[$this->count--]);
|
2003-11-09 14:05:36 +00:00
|
|
|
}
|
|
|
|
$this->ait[0]->rewind();
|
|
|
|
$this->ait[0]->recursed = false;
|
|
|
|
}
|
|
|
|
|
2003-11-22 20:51:15 +00:00
|
|
|
function hasMore()
|
|
|
|
{
|
2003-11-09 14:05:36 +00:00
|
|
|
$count = $this->count;
|
2003-11-22 20:51:15 +00:00
|
|
|
while ($count) {
|
2003-11-09 14:05:36 +00:00
|
|
|
$it = $this->ait[$count];
|
2003-11-22 20:51:15 +00:00
|
|
|
if ($it->hasMore()) {
|
2003-11-09 14:05:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-11-22 20:51:15 +00:00
|
|
|
$count--;
|
2003-11-09 14:05:36 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-11-22 20:51:15 +00:00
|
|
|
function key()
|
|
|
|
{
|
|
|
|
$it = $this->ait[$this->count];
|
2003-11-09 14:05:36 +00:00
|
|
|
return $it->key();
|
|
|
|
}
|
|
|
|
|
2003-11-22 20:51:15 +00:00
|
|
|
function current()
|
|
|
|
{
|
|
|
|
$it = $this->ait[$this->count];
|
2003-11-09 14:05:36 +00:00
|
|
|
return $it->current();
|
|
|
|
}
|
|
|
|
|
2003-11-22 20:51:15 +00:00
|
|
|
function next()
|
|
|
|
{
|
2003-11-09 14:05:36 +00:00
|
|
|
while ($this->count) {
|
2003-11-22 20:51:15 +00:00
|
|
|
$it = $this->ait[$this->count];
|
2003-11-09 14:05:36 +00:00
|
|
|
if ($it->hasMore()) {
|
|
|
|
if (!$it->recursed && $it->hasChildren()) {
|
|
|
|
$it->recursed = true;
|
|
|
|
$sub = $it->getChildren();
|
|
|
|
$sub->recursed = false;
|
|
|
|
$sub->rewind();
|
|
|
|
if ($sub->hasMore()) {
|
2003-11-22 20:51:15 +00:00
|
|
|
$this->ait[++$this->count] = $sub;
|
2004-01-23 21:03:20 +00:00
|
|
|
if (!$sub instanceof RecursiveIterator) {
|
2003-11-09 14:05:36 +00:00
|
|
|
throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unset($sub);
|
|
|
|
}
|
|
|
|
$it->next();
|
|
|
|
$it->recursed = false;
|
|
|
|
if ($it->hasMore()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$it->recursed = false;
|
|
|
|
}
|
2003-11-22 20:51:15 +00:00
|
|
|
if ($this->count) {
|
|
|
|
unset($this->ait[$this->count--]);
|
|
|
|
$it = $this->ait[$this->count];
|
2003-11-09 14:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-22 20:51:15 +00:00
|
|
|
function getSubIterator($level = NULL)
|
|
|
|
{
|
|
|
|
if (is_null($level)) {
|
|
|
|
$level = $this->count;
|
|
|
|
}
|
|
|
|
return @$this->ait[$level];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDepth()
|
|
|
|
{
|
|
|
|
return $this->level;
|
2003-11-09 14:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|