|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MewesK\TwigSpreadsheetBundle\Wrapper; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class PhpSpreadsheetWrapper. |
|
7
|
|
|
*/ |
|
8
|
|
|
class PhpSpreadsheetWrapper |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
const INSTANCE_KEY = '_tsb'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var DocumentWrapper |
|
17
|
|
|
*/ |
|
18
|
|
|
private $documentWrapper; |
|
19
|
|
|
/** |
|
20
|
|
|
* @var SheetWrapper |
|
21
|
|
|
*/ |
|
22
|
|
|
private $sheetWrapper; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var RowWrapper |
|
25
|
|
|
*/ |
|
26
|
|
|
private $rowWrapper; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var CellWrapper |
|
29
|
|
|
*/ |
|
30
|
|
|
private $cellWrapper; |
|
31
|
|
|
/** |
|
32
|
|
|
* @var HeaderFooterWrapper |
|
33
|
|
|
*/ |
|
34
|
|
|
private $headerFooterWrapper; |
|
35
|
|
|
/** |
|
36
|
|
|
* @var DrawingWrapper |
|
37
|
|
|
*/ |
|
38
|
|
|
private $drawingWrapper; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var int|null |
|
42
|
|
|
*/ |
|
43
|
|
|
private $cellIndex; |
|
44
|
|
|
/** |
|
45
|
|
|
* @var int|null |
|
46
|
|
|
*/ |
|
47
|
|
|
private $rowIndex; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* PhpSpreadsheetWrapper constructor. |
|
51
|
|
|
* |
|
52
|
|
|
* @param array $context |
|
53
|
|
|
* @param \Twig_Environment $environment |
|
54
|
|
|
* @param array $attributes |
|
55
|
|
|
*/ |
|
56
|
112 |
|
public function __construct(array $context, \Twig_Environment $environment, array $attributes = []) |
|
57
|
|
|
{ |
|
58
|
112 |
|
$this->documentWrapper = new DocumentWrapper($context, $environment, $attributes); |
|
59
|
112 |
|
$this->sheetWrapper = new SheetWrapper($context, $environment, $this->documentWrapper); |
|
60
|
112 |
|
$this->rowWrapper = new RowWrapper($context, $environment, $this->sheetWrapper); |
|
61
|
112 |
|
$this->cellWrapper = new CellWrapper($context, $environment, $this->sheetWrapper); |
|
62
|
112 |
|
$this->headerFooterWrapper = new HeaderFooterWrapper($context, $environment, $this->sheetWrapper); |
|
63
|
112 |
|
$this->drawingWrapper = new DrawingWrapper($context, $environment, $this->sheetWrapper, $this->headerFooterWrapper, $attributes); |
|
64
|
112 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param array $context |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
100 |
|
public static function fixContext(array $context): array |
|
72
|
|
|
{ |
|
73
|
100 |
|
if (!isset($context[self::INSTANCE_KEY]) && isset($context['varargs']) && \is_array($context['varargs'])) { |
|
74
|
|
|
/** |
|
75
|
|
|
* @var array $args |
|
76
|
|
|
*/ |
|
77
|
3 |
|
$args = $context['varargs']; |
|
78
|
3 |
|
foreach ($args as $arg) { |
|
79
|
3 |
|
if ($arg instanceof self) { |
|
80
|
3 |
|
$context[self::INSTANCE_KEY] = $arg; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
100 |
|
return $context; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param array $properties |
|
90
|
|
|
* |
|
91
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Exception |
|
92
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception |
|
93
|
|
|
* @throws \RuntimeException |
|
94
|
|
|
*/ |
|
95
|
112 |
|
public function startDocument(array $properties = []) |
|
96
|
|
|
{ |
|
97
|
112 |
|
$this->documentWrapper->start($properties); |
|
98
|
112 |
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @throws \LogicException |
|
102
|
|
|
* @throws \InvalidArgumentException |
|
103
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Exception |
|
104
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception |
|
105
|
|
|
* @throws \Symfony\Component\Filesystem\Exception\IOException |
|
106
|
|
|
*/ |
|
107
|
104 |
|
public function endDocument() |
|
108
|
|
|
{ |
|
109
|
104 |
|
$this->documentWrapper->end(); |
|
110
|
104 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param int|string|null $index |
|
114
|
|
|
* @param array $properties |
|
115
|
|
|
* |
|
116
|
|
|
* @throws \LogicException |
|
117
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Exception |
|
118
|
|
|
* @throws \RuntimeException |
|
119
|
|
|
*/ |
|
120
|
100 |
|
public function startSheet($index = null, array $properties = []) |
|
121
|
|
|
{ |
|
122
|
100 |
|
$this->sheetWrapper->start($index, $properties); |
|
123
|
100 |
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @throws \LogicException |
|
127
|
|
|
* @throws \Exception |
|
128
|
|
|
*/ |
|
129
|
92 |
|
public function endSheet() |
|
130
|
|
|
{ |
|
131
|
92 |
|
$this->sheetWrapper->end(); |
|
132
|
92 |
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @throws \LogicException |
|
136
|
|
|
*/ |
|
137
|
77 |
|
public function startRow() |
|
138
|
|
|
{ |
|
139
|
77 |
|
$this->rowWrapper->start($this->rowIndex); |
|
140
|
77 |
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @throws \LogicException |
|
144
|
|
|
*/ |
|
145
|
73 |
|
public function endRow() |
|
146
|
|
|
{ |
|
147
|
73 |
|
$this->rowWrapper->end(); |
|
148
|
73 |
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param null|mixed $value |
|
152
|
|
|
* @param array $properties |
|
153
|
|
|
* |
|
154
|
|
|
* @throws \InvalidArgumentException |
|
155
|
|
|
* @throws \LogicException |
|
156
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Exception |
|
157
|
|
|
* @throws \RuntimeException |
|
158
|
|
|
*/ |
|
159
|
73 |
|
public function startCell($value = null, array $properties = []) |
|
160
|
|
|
{ |
|
161
|
73 |
|
$this->cellWrapper->start($this->cellIndex, $value, $properties); |
|
162
|
73 |
|
} |
|
163
|
|
|
|
|
164
|
73 |
|
public function endCell() |
|
165
|
|
|
{ |
|
166
|
73 |
|
$this->cellWrapper->end(); |
|
167
|
73 |
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param string $baseType |
|
171
|
|
|
* @param string|null $type |
|
172
|
|
|
* @param array $properties |
|
173
|
|
|
* |
|
174
|
|
|
* @throws \LogicException |
|
175
|
|
|
* @throws \RuntimeException |
|
176
|
|
|
* @throws \InvalidArgumentException |
|
177
|
|
|
*/ |
|
178
|
5 |
|
public function startHeaderFooter(string $baseType, string $type = null, array $properties = []) |
|
179
|
|
|
{ |
|
180
|
5 |
|
$this->headerFooterWrapper->start($baseType, $type, $properties); |
|
181
|
5 |
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @throws \LogicException |
|
185
|
|
|
* @throws \InvalidArgumentException |
|
186
|
|
|
*/ |
|
187
|
5 |
|
public function endHeaderFooter() |
|
188
|
|
|
{ |
|
189
|
5 |
|
$this->headerFooterWrapper->end(); |
|
190
|
5 |
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param null|string $type |
|
194
|
|
|
* @param array $properties |
|
195
|
|
|
* |
|
196
|
|
|
* @throws \InvalidArgumentException |
|
197
|
|
|
* @throws \LogicException |
|
198
|
|
|
*/ |
|
199
|
5 |
|
public function startAlignment(string $type = null, array $properties = []) |
|
200
|
|
|
{ |
|
201
|
5 |
|
$this->headerFooterWrapper->startAlignment($type, $properties); |
|
202
|
5 |
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param null|string $value |
|
206
|
|
|
* |
|
207
|
|
|
* @throws \InvalidArgumentException |
|
208
|
|
|
* @throws \LogicException |
|
209
|
|
|
*/ |
|
210
|
5 |
|
public function endAlignment(string $value = null) |
|
211
|
|
|
{ |
|
212
|
5 |
|
$this->headerFooterWrapper->endAlignment($value); |
|
213
|
5 |
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @param string $path |
|
217
|
|
|
* @param array $properties |
|
218
|
|
|
* |
|
219
|
|
|
* @throws \Symfony\Component\Filesystem\Exception\IOException |
|
220
|
|
|
* @throws \InvalidArgumentException |
|
221
|
|
|
* @throws \LogicException |
|
222
|
|
|
* @throws \RuntimeException |
|
223
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Exception |
|
224
|
|
|
*/ |
|
225
|
6 |
|
public function startDrawing(string $path, array $properties = []) |
|
226
|
|
|
{ |
|
227
|
6 |
|
$this->drawingWrapper->start($path, $properties); |
|
228
|
6 |
|
} |
|
229
|
|
|
|
|
230
|
6 |
|
public function endDrawing() |
|
231
|
|
|
{ |
|
232
|
6 |
|
$this->drawingWrapper->end(); |
|
233
|
6 |
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @return int|null |
|
237
|
|
|
*/ |
|
238
|
|
|
public function getCellIndex() |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->cellIndex; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @param int|null $cellIndex |
|
245
|
|
|
*/ |
|
246
|
73 |
|
public function setCellIndex(int $cellIndex = null) |
|
247
|
|
|
{ |
|
248
|
73 |
|
$this->cellIndex = $cellIndex; |
|
249
|
73 |
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @return int|null |
|
253
|
|
|
*/ |
|
254
|
77 |
|
public function getRowIndex() |
|
255
|
|
|
{ |
|
256
|
77 |
|
return $this->rowIndex; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @param int|null $rowIndex |
|
261
|
|
|
*/ |
|
262
|
77 |
|
public function setRowIndex(int $rowIndex = null) |
|
263
|
|
|
{ |
|
264
|
77 |
|
$this->rowIndex = $rowIndex; |
|
265
|
77 |
|
} |
|
266
|
|
|
} |
|
267
|
|
|
|