SpgrContainer.php 1.7 KB

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