SPL-StandardPHPLibrary
recursivecachingiterator.inc
Go to the documentation of this file.
1 <?php
2 
21 {
22  private $hasChildren;
23  private $getChildren;
24 
32  function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING)
33  {
34  parent::__construct($it, $flags);
35  }
36 
39  function rewind();
40  {
41  $this->hasChildren = false;
42  $this->getChildren = NULL;
43  parent::rewind();
44  }
45 
49  function next()
50  {
51  if ($this->hasChildren = $this->it->hasChildren())
52  {
53  try
54  {
55  $child = $this->it->getChildren();
56  if (!$this->ref)
57  {
58  $this->ref = new ReflectionClass($this);
59  }
60  $this->getChildren = $ref->newInstance($child, $this->flags);
61  }
62  catch(Exception $e)
63  {
64  if (!$this->flags & self::CATCH_GET_CHILD)
65  {
66  throw $e;
67  }
68  $this->hasChildren = false;
69  $this->getChildren = NULL;
70  }
71  } else
72  {
73  $this->getChildren = NULL;
74  }
75  parent::next();
76  }
77 
78  private $ref;
79 
86  function hasChildren()
87  {
88  return $this->hasChildren;
89  }
90 
93  function getChildren()
94  {
95  return $this->getChildren;
96  }
97 }
98 
99 ?>
next()
Forward to next element if necessary then an Iterator for the Children will be created.
__construct(RecursiveIterator $it, $flags=self::CALL_TOSTRING)
Construct from another iterator.
Cached iteration over another Iterator.
Cached recursive iteration over another Iterator.
Interface for recursive iteration with RecursiveIteratorIterator.
rewind()
Rewind Iterator.
Basic Exception class.
Definition: spl.php:258