|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Creator; |
|
4
|
|
|
|
|
5
|
|
|
use Box\Spout\Common\Creator\HelperFactory; |
|
6
|
|
|
use Box\Spout\Common\Entity\Cell; |
|
7
|
|
|
use Box\Spout\Common\Entity\Row; |
|
8
|
|
|
use Box\Spout\Common\Entity\Style\Style; |
|
9
|
|
|
use Box\Spout\Common\Helper\GlobalFunctionsHelper; |
|
10
|
|
|
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; |
|
11
|
|
|
use Box\Spout\Writer\CSV\Manager\OptionsManager as CSVOptionsManager; |
|
12
|
|
|
use Box\Spout\Writer\CSV\Writer as CSVWriter; |
|
13
|
|
|
use Box\Spout\Writer\ODS\Creator\HelperFactory as ODSHelperFactory; |
|
14
|
|
|
use Box\Spout\Writer\ODS\Creator\ManagerFactory as ODSManagerFactory; |
|
15
|
|
|
use Box\Spout\Writer\ODS\Manager\OptionsManager as ODSOptionsManager; |
|
16
|
|
|
use Box\Spout\Writer\ODS\Writer as ODSWriter; |
|
17
|
|
|
use Box\Spout\Writer\WriterInterface; |
|
18
|
|
|
use Box\Spout\Writer\XLSX\Creator\HelperFactory as XLSXHelperFactory; |
|
19
|
|
|
use Box\Spout\Writer\XLSX\Creator\ManagerFactory as XLSXManagerFactory; |
|
20
|
|
|
use Box\Spout\Writer\XLSX\Manager\OptionsManager as XLSXOptionsManager; |
|
21
|
|
|
use Box\Spout\Writer\XLSX\Writer as XLSXWriter; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class WriterEntityFactory |
|
25
|
|
|
* Factory to create external entities |
|
26
|
|
|
*/ |
|
27
|
|
|
class WriterEntityFactory |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* This creates an instance of the appropriate writer, given the type of the file to be written |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $writerType Type of the writer to instantiate |
|
33
|
|
|
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException |
|
34
|
|
|
* @return WriterInterface |
|
35
|
|
|
*/ |
|
36
|
96 |
|
public static function createWriter($writerType) |
|
37
|
|
|
{ |
|
38
|
96 |
|
return (new WriterFactory())->create($writerType); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return \Box\Spout\Writer\CSV\Writer |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function createCSVWriter() |
|
45
|
|
|
{ |
|
46
|
|
|
$optionsManager = new CSVOptionsManager(); |
|
47
|
|
|
$globalFunctionsHelper = new GlobalFunctionsHelper(); |
|
48
|
|
|
|
|
49
|
|
|
$helperFactory = new HelperFactory(); |
|
50
|
|
|
|
|
51
|
|
|
return new CSVWriter($optionsManager, $globalFunctionsHelper, $helperFactory); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return \Box\Spout\Writer\XLSX\Writer |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function createXLSXWriter() |
|
58
|
|
|
{ |
|
59
|
|
|
$styleBuilder = new StyleBuilder(); |
|
60
|
|
|
$optionsManager = new XLSXOptionsManager($styleBuilder); |
|
61
|
|
|
$globalFunctionsHelper = new GlobalFunctionsHelper(); |
|
62
|
|
|
|
|
63
|
|
|
$helperFactory = new XLSXHelperFactory(); |
|
64
|
|
|
$managerFactory = new XLSXManagerFactory(new InternalEntityFactory(), $helperFactory); |
|
65
|
|
|
|
|
66
|
|
|
return new XLSXWriter($optionsManager, $globalFunctionsHelper, $helperFactory, $managerFactory); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return \Box\Spout\Writer\ODS\Writer |
|
71
|
|
|
*/ |
|
72
|
|
|
public static function createODSWriter() |
|
73
|
|
|
{ |
|
74
|
|
|
$styleBuilder = new StyleBuilder(); |
|
75
|
|
|
$optionsManager = new ODSOptionsManager($styleBuilder); |
|
76
|
|
|
$globalFunctionsHelper = new GlobalFunctionsHelper(); |
|
77
|
|
|
|
|
78
|
|
|
$helperFactory = new ODSHelperFactory(); |
|
79
|
|
|
$managerFactory = new ODSManagerFactory(new InternalEntityFactory(), $helperFactory); |
|
80
|
|
|
|
|
81
|
|
|
return new ODSWriter($optionsManager, $globalFunctionsHelper, $helperFactory, $managerFactory); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param Cell[] $cells |
|
87
|
|
|
* @param Style|null $rowStyle |
|
88
|
|
|
* @return Row |
|
89
|
|
|
*/ |
|
90
|
2 |
|
public static function createRow(array $cells = [], Style $rowStyle = null) |
|
91
|
|
|
{ |
|
92
|
2 |
|
return new Row($cells, $rowStyle); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param array $cellValues |
|
97
|
|
|
* @param Style|null $rowStyle |
|
98
|
|
|
* @return Row |
|
99
|
|
|
*/ |
|
100
|
78 |
|
public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null) |
|
101
|
|
|
{ |
|
102
|
|
|
$cells = array_map(function ($cellValue) { |
|
103
|
78 |
|
return new Cell($cellValue); |
|
104
|
78 |
|
}, $cellValues); |
|
105
|
|
|
|
|
106
|
78 |
|
return new Row($cells, $rowStyle); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param mixed $cellValue |
|
111
|
|
|
* @param Style|null $cellStyle |
|
112
|
|
|
* @return Cell |
|
113
|
|
|
*/ |
|
114
|
2 |
|
public static function createCell($cellValue, Style $cellStyle = null) |
|
115
|
|
|
{ |
|
116
|
2 |
|
return new Cell($cellValue, $cellStyle); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|