|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Creator; |
|
4
|
|
|
|
|
5
|
|
|
use Box\Spout\Common\Creator\HelperFactory; |
|
6
|
|
|
use Box\Spout\Common\Exception\UnsupportedTypeException; |
|
7
|
|
|
use Box\Spout\Common\Helper\GlobalFunctionsHelper; |
|
8
|
|
|
use Box\Spout\Common\Type; |
|
9
|
|
|
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; |
|
10
|
|
|
use Box\Spout\Writer\CSV\Manager\OptionsManager as CSVOptionsManager; |
|
11
|
|
|
use Box\Spout\Writer\CSV\Writer as CSVWriter; |
|
12
|
|
|
use Box\Spout\Writer\ODS\Creator\HelperFactory as ODSHelperFactory; |
|
13
|
|
|
use Box\Spout\Writer\ODS\Creator\ManagerFactory as ODSManagerFactory; |
|
14
|
|
|
use Box\Spout\Writer\ODS\Manager\OptionsManager as ODSOptionsManager; |
|
15
|
|
|
use Box\Spout\Writer\ODS\Writer as ODSWriter; |
|
16
|
|
|
use Box\Spout\Writer\WriterInterface; |
|
17
|
|
|
use Box\Spout\Writer\XLSX\Creator\HelperFactory as XLSXHelperFactory; |
|
18
|
|
|
use Box\Spout\Writer\XLSX\Creator\ManagerFactory as XLSXManagerFactory; |
|
19
|
|
|
use Box\Spout\Writer\XLSX\Manager\OptionsManager as XLSXOptionsManager; |
|
20
|
|
|
use Box\Spout\Writer\XLSX\Writer as XLSXWriter; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class WriterFactory |
|
24
|
|
|
* This factory is used to create writers, based on the type of the file to be read. |
|
25
|
|
|
* It supports CSV, XLSX and ODS formats. |
|
26
|
|
|
*/ |
|
27
|
|
|
class WriterFactory |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* This creates an instance of the appropriate writer, given the type of the file to be read |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $writerType Type of the writer to instantiate |
|
33
|
|
|
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException |
|
34
|
|
|
* @return WriterInterface |
|
35
|
|
|
*/ |
|
36
|
95 |
|
public function create($writerType) |
|
37
|
|
|
{ |
|
38
|
|
|
switch ($writerType) { |
|
39
|
95 |
|
case Type::CSV: return $this->getCSVWriter(); |
|
40
|
84 |
|
case Type::XLSX: return $this->getXLSXWriter(); |
|
41
|
41 |
|
case Type::ODS: return $this->getODSWriter(); |
|
42
|
|
|
default: |
|
43
|
1 |
|
throw new UnsupportedTypeException('No writers supporting the given type: ' . $writerType); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return CSVWriter |
|
49
|
|
|
*/ |
|
50
|
11 |
|
private function getCSVWriter() |
|
51
|
|
|
{ |
|
52
|
11 |
|
$optionsManager = new CSVOptionsManager(); |
|
53
|
11 |
|
$globalFunctionsHelper = new GlobalFunctionsHelper(); |
|
54
|
|
|
|
|
55
|
11 |
|
$helperFactory = new HelperFactory(); |
|
56
|
|
|
|
|
57
|
11 |
|
return new CSVWriter($optionsManager, $globalFunctionsHelper, $helperFactory); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return XLSXWriter |
|
62
|
|
|
*/ |
|
63
|
43 |
|
private function getXLSXWriter() |
|
64
|
|
|
{ |
|
65
|
43 |
|
$styleBuilder = new StyleBuilder(); |
|
66
|
43 |
|
$optionsManager = new XLSXOptionsManager($styleBuilder); |
|
67
|
43 |
|
$globalFunctionsHelper = new GlobalFunctionsHelper(); |
|
68
|
|
|
|
|
69
|
43 |
|
$helperFactory = new XLSXHelperFactory(); |
|
70
|
43 |
|
$managerFactory = new XLSXManagerFactory(new InternalEntityFactory(), $helperFactory); |
|
71
|
|
|
|
|
72
|
43 |
|
return new XLSXWriter($optionsManager, $globalFunctionsHelper, $helperFactory, $managerFactory); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return ODSWriter |
|
77
|
|
|
*/ |
|
78
|
40 |
|
private function getODSWriter() |
|
79
|
|
|
{ |
|
80
|
40 |
|
$styleBuilder = new StyleBuilder(); |
|
81
|
40 |
|
$optionsManager = new ODSOptionsManager($styleBuilder); |
|
82
|
40 |
|
$globalFunctionsHelper = new GlobalFunctionsHelper(); |
|
83
|
|
|
|
|
84
|
40 |
|
$helperFactory = new ODSHelperFactory(); |
|
85
|
40 |
|
$managerFactory = new ODSManagerFactory(new InternalEntityFactory(), $helperFactory); |
|
86
|
|
|
|
|
87
|
40 |
|
return new ODSWriter($optionsManager, $globalFunctionsHelper, $helperFactory, $managerFactory); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|