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