FrameListIterator.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace Dompdf\Frame;
  3. use Iterator;
  4. use Dompdf\Frame;
  5. /**
  6. * Linked-list Iterator
  7. *
  8. * Returns children in order and allows for list to change during iteration,
  9. * provided the changes occur to or after the current element
  10. *
  11. * @access private
  12. * @package dompdf
  13. */
  14. class FrameListIterator implements Iterator
  15. {
  16. /**
  17. * @var Frame
  18. */
  19. protected $_parent;
  20. /**
  21. * @var Frame
  22. */
  23. protected $_cur;
  24. /**
  25. * @var int
  26. */
  27. protected $_num;
  28. /**
  29. * @param Frame $frame
  30. */
  31. public function __construct(Frame $frame)
  32. {
  33. $this->_parent = $frame;
  34. $this->_cur = $frame->get_first_child();
  35. $this->_num = 0;
  36. }
  37. /**
  38. *
  39. */
  40. public function rewind()
  41. {
  42. $this->_cur = $this->_parent->get_first_child();
  43. $this->_num = 0;
  44. }
  45. /**
  46. * @return bool
  47. */
  48. public function valid()
  49. {
  50. return isset($this->_cur); // && ($this->_cur->get_prev_sibling() === $this->_prev);
  51. }
  52. /**
  53. * @return int
  54. */
  55. public function key()
  56. {
  57. return $this->_num;
  58. }
  59. /**
  60. * @return Frame
  61. */
  62. public function current()
  63. {
  64. return $this->_cur;
  65. }
  66. /**
  67. * @return Frame
  68. */
  69. public function next()
  70. {
  71. $ret = $this->_cur;
  72. if (!$ret) {
  73. return null;
  74. }
  75. $this->_cur = $this->_cur->get_next_sibling();
  76. $this->_num++;
  77. return $ret;
  78. }
  79. }