tablepress
/
libraries
/
vendor
/
PhpSpreadsheet
/
Shared
/
Escher
/
DgContainer
/
SpgrContainer.php
SpgrContainer.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Shared/Escher/DgContainer/SpgrContainer.php
| 1 | <?php |
| 2 | |
| 3 | namespace TablePress\PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer; |
| 4 | |
| 5 | class SpgrContainer |
| 6 | { |
| 7 | /** |
| 8 | * Parent Shape Group Container. |
| 9 | */ |
| 10 | private ?self $parent = null; |
| 11 | |
| 12 | /** |
| 13 | * Shape Container collection. |
| 14 | * |
| 15 | * @var mixed[] |
| 16 | */ |
| 17 | private array $children = []; |
| 18 | |
| 19 | /** |
| 20 | * Set parent Shape Group Container. |
| 21 | */ |
| 22 | public function setParent(?self $parent): void |
| 23 | { |
| 24 | $this->parent = $parent; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Get the parent Shape Group Container if any. |
| 29 | */ |
| 30 | public function getParent(): ?self |
| 31 | { |
| 32 | return $this->parent; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Add a child. This will be either spgrContainer or spContainer. |
| 37 | * |
| 38 | * @param mixed $child child to be added |
| 39 | */ |
| 40 | public function addChild($child): void |
| 41 | { |
| 42 | $this->children[] = $child; |
| 43 | $child->setParent($this); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get collection of Shape Containers. |
| 48 | * |
| 49 | * @return mixed[] |
| 50 | */ |
| 51 | public function getChildren(): array |
| 52 | { |
| 53 | return $this->children; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Recursively get all spContainers within this spgrContainer. |
| 58 | * |
| 59 | * @return SpgrContainer\SpContainer[] |
| 60 | */ |
| 61 | public function getAllSpContainers(): array |
| 62 | { |
| 63 | $allSpContainers = []; |
| 64 | |
| 65 | foreach ($this->children as $child) { |
| 66 | if ($child instanceof self) { |
| 67 | $allSpContainers = array_merge($allSpContainers, $child->getAllSpContainers()); |
| 68 | } else { |
| 69 | $allSpContainers[] = $child; |
| 70 | } |
| 71 | } |
| 72 | /** @var SpgrContainer\SpContainer[] $allSpContainers */ |
| 73 | |
| 74 | return $allSpContainers; |
| 75 | } |
| 76 | } |
| 77 |