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