1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\XLSX\Creator; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Common\Escaper; |
6
|
|
|
use Box\Spout\Common\Helper\StringHelper; |
7
|
|
|
use Box\Spout\Writer\Common\Creator\EntityFactory; |
8
|
|
|
use Box\Spout\Writer\Common\Creator\InternalFactoryInterface; |
9
|
|
|
use Box\Spout\Writer\Common\Entity\Options; |
10
|
|
|
use Box\Spout\Writer\Common\Helper\ZipHelper; |
11
|
|
|
use Box\Spout\Writer\Common\Manager\OptionsManagerInterface; |
12
|
|
|
use Box\Spout\Writer\XLSX\Helper\FileSystemHelper; |
13
|
|
|
use Box\Spout\Writer\XLSX\Manager\SharedStringsManager; |
14
|
|
|
use Box\Spout\Writer\XLSX\Manager\Style\StyleManager; |
15
|
|
|
use Box\Spout\Writer\XLSX\Manager\Style\StyleRegistry; |
16
|
|
|
use Box\Spout\Writer\XLSX\Manager\WorkbookManager; |
17
|
|
|
use Box\Spout\Writer\XLSX\Manager\WorksheetManager; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class InternalFactory |
21
|
|
|
* Factory for all useful types of objects needed by the XLSX Writer |
22
|
|
|
* |
23
|
|
|
* @package Box\Spout\Writer\XLSX\Creator |
24
|
|
|
*/ |
25
|
|
|
class InternalFactory implements InternalFactoryInterface |
26
|
|
|
{ |
27
|
|
|
/** @var EntityFactory */ |
28
|
|
|
private $entityFactory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* InternalFactory constructor. |
32
|
|
|
* |
33
|
|
|
* @param EntityFactory $entityFactory |
34
|
|
|
*/ |
35
|
51 |
|
public function __construct(EntityFactory $entityFactory) |
36
|
|
|
{ |
37
|
51 |
|
$this->entityFactory = $entityFactory; |
38
|
51 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param OptionsManagerInterface $optionsManager |
42
|
|
|
* @return WorkbookManager |
43
|
|
|
*/ |
44
|
46 |
|
public function createWorkbookManager(OptionsManagerInterface $optionsManager) |
45
|
|
|
{ |
46
|
46 |
|
$workbook = $this->entityFactory->createWorkbook(); |
47
|
|
|
|
48
|
46 |
|
$fileSystemHelper = $this->createFileSystemHelper($optionsManager); |
49
|
46 |
|
$fileSystemHelper->createBaseFilesAndFolders(); |
50
|
|
|
|
51
|
46 |
|
$xlFolder = $fileSystemHelper->getXlFolder(); |
52
|
46 |
|
$sharedStringsManager = $this->createSharedStringsManager($xlFolder); |
53
|
|
|
|
54
|
46 |
|
$styleManager = $this->createStyleManager($optionsManager); |
55
|
46 |
|
$worksheetManager = $this->createWorksheetManager($optionsManager, $styleManager, $sharedStringsManager); |
56
|
|
|
|
57
|
46 |
|
return new WorkbookManager($workbook, $optionsManager, $worksheetManager, $styleManager, $fileSystemHelper, $this->entityFactory); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param OptionsManagerInterface $optionsManager |
62
|
|
|
* @param StyleManager $styleManager |
63
|
|
|
* @param SharedStringsManager $sharedStringsManager |
64
|
|
|
* @return WorksheetManager |
65
|
|
|
*/ |
66
|
46 |
|
private function createWorksheetManager( |
67
|
|
|
OptionsManagerInterface $optionsManager, |
68
|
|
|
StyleManager $styleManager, |
69
|
|
|
SharedStringsManager $sharedStringsManager |
70
|
|
|
) |
71
|
|
|
{ |
72
|
46 |
|
$stringsEscaper = $this->createStringsEscaper(); |
73
|
46 |
|
$stringsHelper = $this->createStringHelper(); |
74
|
|
|
|
75
|
46 |
|
return new WorksheetManager($optionsManager, $styleManager, $sharedStringsManager, $stringsEscaper, $stringsHelper); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param OptionsManagerInterface $optionsManager |
80
|
|
|
* @return StyleManager |
81
|
|
|
*/ |
82
|
46 |
|
private function createStyleManager(OptionsManagerInterface $optionsManager) |
83
|
|
|
{ |
84
|
46 |
|
$styleRegistry = $this->createStyleRegistry($optionsManager); |
85
|
46 |
|
return new StyleManager($styleRegistry); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param OptionsManagerInterface $optionsManager |
90
|
|
|
* @return StyleRegistry |
91
|
|
|
*/ |
92
|
46 |
|
private function createStyleRegistry(OptionsManagerInterface $optionsManager) |
93
|
|
|
{ |
94
|
46 |
|
$defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE); |
95
|
46 |
|
return new StyleRegistry($defaultRowStyle); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $xlFolder Path to the "xl" folder |
100
|
|
|
* @return SharedStringsManager |
101
|
|
|
*/ |
102
|
46 |
|
private function createSharedStringsManager($xlFolder) |
103
|
|
|
{ |
104
|
46 |
|
$stringEscaper = $this->createStringsEscaper(); |
105
|
46 |
|
return new SharedStringsManager($xlFolder, $stringEscaper); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param OptionsManagerInterface $optionsManager |
110
|
|
|
* @return FileSystemHelper |
111
|
|
|
*/ |
112
|
46 |
|
private function createFileSystemHelper(OptionsManagerInterface $optionsManager) |
113
|
|
|
{ |
114
|
46 |
|
$tempFolder = $optionsManager->getOption(Options::TEMP_FOLDER); |
115
|
46 |
|
$zipHelper = $this->createZipHelper(); |
116
|
|
|
|
117
|
46 |
|
return new FileSystemHelper($tempFolder, $zipHelper); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return ZipHelper |
122
|
|
|
*/ |
123
|
46 |
|
private function createZipHelper() |
124
|
|
|
{ |
125
|
46 |
|
return new ZipHelper(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return Escaper\XLSX |
130
|
|
|
*/ |
131
|
46 |
|
private function createStringsEscaper() |
132
|
|
|
{ |
133
|
46 |
|
return Escaper\XLSX::getInstance(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return StringHelper |
138
|
|
|
*/ |
139
|
46 |
|
private function createStringHelper() |
140
|
|
|
{ |
141
|
46 |
|
return new StringHelper(); |
142
|
|
|
} |
143
|
|
|
} |