PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.2
2.4.3 2.4.4 2.4.2 2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 All 60 releases
easy-invoice / vendor / dompdf / dompdf / src / Frame / FrameTreeIterator.php

FrameTreeIterator.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.2, at vendor/dompdf/dompdf/src/Frame/FrameTreeIterator.php

89 lines 1.5 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 * Pre-order Iterator
14 *
15 * Returns frames in preorder traversal order (parent then children)
16 *
17 * @package dompdf
18 */
19 class FrameTreeIterator implements Iterator
20 {
21 /**
22 * @var Frame
23 */
24 protected $_root;
25
26 /**
27 * @var Frame[]
28 */
29 protected $_stack = [];
30
31 /**
32 * @var int
33 */
34 protected $_num;
35
36 /**
37 * @param Frame $root
38 */
39 public function __construct(Frame $root)
40 {
41 $this->_stack[] = $this->_root = $root;
42 $this->_num = 0;
43 }
44
45 public function rewind(): void
46 {
47 $this->_stack = [$this->_root];
48 $this->_num = 0;
49 }
50
51 /**
52 * @return bool
53 */
54 public function valid(): bool
55 {
56 return count($this->_stack) > 0;
57 }
58
59 /**
60 * @return int
61 */
62 public function key(): int
63 {
64 return $this->_num;
65 }
66
67 /**
68 * @return Frame
69 */
70 public function current(): Frame
71 {
72 return end($this->_stack);
73 }
74
75 public function next(): void
76 {
77 $b = array_pop($this->_stack);
78 $this->_num++;
79
80 // Push all children onto the stack in reverse order
81 if ($c = $b->get_last_child()) {
82 $this->_stack[] = $c;
83 while ($c = $c->get_prev_sibling()) {
84 $this->_stack[] = $c;
85 }
86 }
87 }
88 }
89