Supervisor.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Style;
  3. use PhpOffice\PhpSpreadsheet\IComparable;
  4. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  5. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  6. abstract class Supervisor implements IComparable
  7. {
  8. /**
  9. * Supervisor?
  10. *
  11. * @var bool
  12. */
  13. protected $isSupervisor;
  14. /**
  15. * Parent. Only used for supervisor.
  16. *
  17. * @var Spreadsheet|Style
  18. */
  19. protected $parent;
  20. /**
  21. * Parent property name.
  22. *
  23. * @var null|string
  24. */
  25. protected $parentPropertyName;
  26. /**
  27. * Create a new Supervisor.
  28. *
  29. * @param bool $isSupervisor Flag indicating if this is a supervisor or not
  30. * Leave this value at default unless you understand exactly what
  31. * its ramifications are
  32. */
  33. public function __construct($isSupervisor = false)
  34. {
  35. // Supervisor?
  36. $this->isSupervisor = $isSupervisor;
  37. }
  38. /**
  39. * Bind parent. Only used for supervisor.
  40. *
  41. * @param Spreadsheet|Style $parent
  42. * @param null|string $parentPropertyName
  43. *
  44. * @return Supervisor
  45. */
  46. public function bindParent($parent, $parentPropertyName = null)
  47. {
  48. $this->parent = $parent;
  49. $this->parentPropertyName = $parentPropertyName;
  50. return $this;
  51. }
  52. /**
  53. * Is this a supervisor or a cell style component?
  54. *
  55. * @return bool
  56. */
  57. public function getIsSupervisor()
  58. {
  59. return $this->isSupervisor;
  60. }
  61. /**
  62. * Get the currently active sheet. Only used for supervisor.
  63. *
  64. * @return Worksheet
  65. */
  66. public function getActiveSheet()
  67. {
  68. return $this->parent->getActiveSheet();
  69. }
  70. /**
  71. * Get the currently active cell coordinate in currently active sheet.
  72. * Only used for supervisor.
  73. *
  74. * @return string E.g. 'A1'
  75. */
  76. public function getSelectedCells()
  77. {
  78. return $this->getActiveSheet()->getSelectedCells();
  79. }
  80. /**
  81. * Get the currently active cell coordinate in currently active sheet.
  82. * Only used for supervisor.
  83. *
  84. * @return string E.g. 'A1'
  85. */
  86. public function getActiveCell()
  87. {
  88. return $this->getActiveSheet()->getActiveCell();
  89. }
  90. /**
  91. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  92. */
  93. public function __clone()
  94. {
  95. $vars = get_object_vars($this);
  96. foreach ($vars as $key => $value) {
  97. if ((is_object($value)) && ($key != 'parent')) {
  98. $this->$key = clone $value;
  99. } else {
  100. $this->$key = $value;
  101. }
  102. }
  103. }
  104. }