php-src/ext/spl/examples/cachingrecursiveiterator.inc

47 lines
974 B
PHP
Raw Normal View History

2003-11-18 22:18:38 +00:00
<?php
class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator
{
protected $hasChildren;
protected $getChildren;
2003-11-22 20:51:15 +00:00
protected $catch_get_child;
2003-11-18 22:18:38 +00:00
2003-12-08 08:31:08 +00:00
function __construct(RecursiveIterator $it, $flags = CIT_CALL_TOSTRING)
2003-11-22 20:51:15 +00:00
{
parent::__construct($it, $flags);
2003-11-18 22:18:38 +00:00
}
2003-11-22 20:51:15 +00:00
function next()
{
2003-11-18 22:18:38 +00:00
if ($this->hasChildren = $this->it->hasChildren()) {
try {
//$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->flags);
// workaround memleaks...
$child = $this->it->getChildren();
$this->getChildren = new CachingRecursiveIterator($child, $this->flags);
}
catch(Exception $e) {
if (!$this->flags & CIT_CATCH_GET_CHILD) {
throw $e;
}
$this->hasChildren = false;
$this->getChildren = NULL;
}
2003-11-18 22:18:38 +00:00
} else {
$this->getChildren = NULL;
}
parent::next();
}
2003-11-22 20:51:15 +00:00
function hasChildren()
{
2003-11-18 22:18:38 +00:00
return $this->hasChildren;
}
2003-11-22 20:51:15 +00:00
function getChildren()
{
2003-11-18 22:18:38 +00:00
return $this->getChildren;
}
}
?>