PluginProbe
MBE eShip / trunk
MBE eShip vtrunk
2.8.1 trunk 1.0.0 1.1.0 1.1.3 1.2.1 1.2.2 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.7.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.2.1 All 37 releases
mail-boxes-etc / lib / dompdf / src / Frame / FrameListIterator.php

FrameListIterator.php in MBE eShip trunk, at lib/dompdf/src/Frame/FrameListIterator.php

101 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package dompdf
4 * @link https://github.com/dompdf/dompdf
5 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
6 */
7 namespace Dompdf\Frame;
8
9 use Iterator;
10 use Dompdf\Frame;
11
12 /**
13 * Linked-list Iterator
14 *
15 * Returns children in order and allows for the list to change during iteration,
16 * provided the changes occur to or after the current element.
17 *
18 * @package dompdf
19 */
20 class FrameListIterator implements Iterator
21 {
22 /**
23 * @var Frame
24 */
25 protected $parent;
26
27 /**
28 * @var Frame|null
29 */
30 protected $cur;
31
32 /**
33 * @var Frame|null
34 */
35 protected $prev;
36
37 /**
38 * @var int
39 */
40 protected $num;
41
42 /**
43 * @param Frame $frame
44 */
45 public function __construct(Frame $frame)
46 {
47 $this->parent = $frame;
48 $this->rewind();
49 }
50
51 public function rewind(): void
52 {
53 $this->cur = $this->parent->get_first_child();
54 $this->prev = null;
55 $this->num = 0;
56 }
57
58 /**
59 * @return bool
60 */
61 public function valid(): bool
62 {
63 return $this->cur !== null;
64 }
65
66 /**
67 * @return int
68 */
69 public function key(): int
70 {
71 return $this->num;
72 }
73
74 /**
75 * @return Frame|null
76 */
77 public function current(): ?Frame
78 {
79 return $this->cur;
80 }
81
82 public function next(): void
83 {
84 if ($this->cur === null) {
85 return;
86 }
87
88 if ($this->cur->get_parent() === $this->parent) {
89 $this->prev = $this->cur;
90 $this->cur = $this->cur->get_next_sibling();
91 $this->num++;
92 } else {
93 // Continue from the previous child if the current frame has been
94 // moved to another parent
95 $this->cur = $this->prev !== null
96 ? $this->prev->get_next_sibling()
97 : $this->parent->get_first_child();
98 }
99 }
100 }
101