blob: 898d40b0bcdabe6db020ad97ae68d1b02b17970d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator
{
protected $hasChildren;
protected $getChildren;
protected $catch_get_child;
function __construct(RecursiveIterator $it, $getStrVal = true, $catch_get_child = false)
{
$this->catch_get_child = $catch_get_child;
parent::__construct($it, $getStrVal);
}
function next()
{
if ($this->hasChildren = $this->it->hasChildren()) {
try {
//$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->getStrVal, $this->catch_get_child);
// workaround memleaks...
$child = $this->it->getChildren();
$this->getChildren = new CachingRecursiveIterator($child, $this->getStrVal, $this->catch_get_child);
}
catch(Exception $e) {
if (!$this->catch_get_child) {
throw $e;
}
$this->hasChildren = false;
$this->getChildren = NULL;
}
} else {
$this->getChildren = NULL;
}
parent::next();
}
function hasChildren()
{
return $this->hasChildren;
}
function getChildren()
{
return $this->getChildren;
}
}
?>
|