PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Style / Supervisor.php

Supervisor.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/Supervisor.php

170 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Style;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\IComparable;
6 use TablePress\PhpOffice\PhpSpreadsheet\Spreadsheet;
7 use TablePress\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
8
9 abstract class Supervisor implements IComparable
10 {
11 /**
12 * Supervisor?
13 */
14 protected bool $isSupervisor;
15
16 /**
17 * Parent. Only used for supervisor.
18 *
19 * @var Spreadsheet|Supervisor
20 */
21 protected $parent;
22
23 /**
24 * Parent property name.
25 */
26 protected ?string $parentPropertyName = null;
27
28 /**
29 * Create a new Supervisor.
30 *
31 * @param bool $isSupervisor Flag indicating if this is a supervisor or not
32 * Leave this value at default unless you understand exactly what
33 * its ramifications are
34 */
35 public function __construct(bool $isSupervisor = false)
36 {
37 // Supervisor?
38 $this->isSupervisor = $isSupervisor;
39 }
40
41 /**
42 * Bind parent. Only used for supervisor.
43 *
44 * @return $this
45 * @param \TablePress\PhpOffice\PhpSpreadsheet\Spreadsheet|$this $parent
46 */
47 public function bindParent($parent, ?string $parentPropertyName = null)
48 {
49 $this->parent = $parent;
50 $this->parentPropertyName = $parentPropertyName;
51
52 return $this;
53 }
54
55 /**
56 * Is this a supervisor or a cell style component?
57 */
58 public function getIsSupervisor(): bool
59 {
60 return $this->isSupervisor;
61 }
62
63 /**
64 * Get the currently active sheet. Only used for supervisor.
65 */
66 public function getActiveSheet(): Worksheet
67 {
68 return $this->parent->getActiveSheet();
69 }
70
71 /**
72 * Get the currently active cell coordinate in currently active sheet.
73 * Only used for supervisor.
74 *
75 * @return string E.g. 'A1'
76 */
77 public function getSelectedCells(): string
78 {
79 return $this->getActiveSheet()->getSelectedCells();
80 }
81
82 /**
83 * Get the currently active cell coordinate in currently active sheet.
84 * Only used for supervisor.
85 *
86 * @return string E.g. 'A1'
87 */
88 public function getActiveCell(): string
89 {
90 return $this->getActiveSheet()->getActiveCell();
91 }
92
93 /**
94 * Implement PHP __clone to create a deep clone, not just a shallow copy.
95 */
96 public function __clone()
97 {
98 $vars = get_object_vars($this);
99 foreach ($vars as $key => $value) {
100 if ((is_object($value)) && ($key != 'parent')) {
101 $this->$key = clone $value;
102 } else {
103 $this->$key = $value;
104 }
105 }
106 }
107
108 /**
109 * Export style as array.
110 *
111 * Available to anything which extends this class:
112 * Alignment, Border, Borders, Color, Fill, Font,
113 * NumberFormat, Protection, and Style.
114 *
115 * @return mixed[]
116 */
117 final public function exportArray(): array
118 {
119 return $this->exportArray1();
120 }
121
122 /**
123 * Abstract method to be implemented in anything which
124 * extends this class.
125 *
126 * This method invokes exportArray2 with the names and values
127 * of all properties to be included in output array,
128 * returning that array to exportArray, then to caller.
129 *
130 * @return mixed[]
131 */
132 abstract protected function exportArray1(): array;
133
134 /**
135 * Populate array from exportArray1.
136 * This method is available to anything which extends this class.
137 * The parameter index is the key to be added to the array.
138 * The parameter objOrValue is either a primitive type,
139 * which is the value added to the array,
140 * or a Style object to be recursively added via exportArray.
141 *
142 * @param mixed[] $exportedArray
143 * @param mixed $objOrValue
144 */
145 final protected function exportArray2(array &$exportedArray, string $index, $objOrValue): void
146 {
147 if ($objOrValue instanceof self) {
148 $exportedArray[$index] = $objOrValue->exportArray();
149 } else {
150 $exportedArray[$index] = $objOrValue;
151 }
152 }
153
154 /**
155 * Get the shared style component for the currently active cell in currently active sheet.
156 * Only used for style supervisor.
157 * @return mixed
158 */
159 abstract public function getSharedComponent();
160
161 /**
162 * Build style array from subcomponents.
163 *
164 * @param mixed[] $array
165 *
166 * @return mixed[]
167 */
168 abstract public function getStyleArray(array $array): array;
169 }
170