FrameTreeIterator

Pre-order Iterator.

Defined (1)

The class is defined in the following location(s).

/lib/dompdf/include/frame.cls.php  
  1. class FrameTreeIterator implements Iterator { 
  2. /** 
  3. * @var Frame 
  4. */ 
  5. protected $_root; 
  6. protected $_stack = array(); 
  7.  
  8. /** 
  9. * @var int 
  10. */ 
  11. protected $_num; 
  12.  
  13. function __construct(Frame $root) { 
  14. $this->_stack[] = $this->_root = $root; 
  15. $this->_num = 0; 
  16.  
  17. function rewind() { 
  18. $this->_stack = array($this->_root); 
  19. $this->_num = 0; 
  20.  
  21. /** 
  22. * @return bool 
  23. */ 
  24. function valid() { 
  25. return count($this->_stack) > 0; 
  26.  
  27. /** 
  28. * @return int 
  29. */ 
  30. function key() { 
  31. return $this->_num; 
  32.  
  33. /** 
  34. * @return Frame 
  35. */ 
  36. function current() { 
  37. return end($this->_stack); 
  38.  
  39. /** 
  40. * @return Frame 
  41. */ 
  42. function next() { 
  43. $b = end($this->_stack); 
  44.  
  45. // Pop last element 
  46. unset($this->_stack[ key($this->_stack) ]); 
  47. $this->_num++; 
  48.  
  49. // Push all children onto the stack in reverse order 
  50. if ( $c = $b->get_last_child() ) { 
  51. $this->_stack[] = $c; 
  52. while ( $c = $c->get_prev_sibling() ) { 
  53. $this->_stack[] = $c; 
  54.  
  55. return $b;