1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\ODS\Creator; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Common\Helper\StringHelper; |
6
|
|
|
use Box\Spout\Writer\Common\Helper\ZipHelper; |
7
|
|
|
use Box\Spout\Writer\Common\Manager\OptionsManagerInterface; |
8
|
|
|
use Box\Spout\Writer\Common\Entity\Options; |
9
|
|
|
use Box\Spout\Writer\Common\Creator\EntityFactory; |
10
|
|
|
use Box\Spout\Writer\Common\Creator\InternalFactoryInterface; |
11
|
|
|
use Box\Spout\Writer\ODS\Helper\FileSystemHelper; |
12
|
|
|
use Box\Spout\Writer\ODS\Manager\Style\StyleManager; |
13
|
|
|
use Box\Spout\Writer\ODS\Manager\Style\StyleRegistry; |
14
|
|
|
use Box\Spout\Writer\ODS\Manager\WorkbookManager; |
15
|
|
|
use Box\Spout\Writer\ODS\Manager\WorksheetManager; |
16
|
|
|
use \Box\Spout\Common\Escaper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class InternalFactory |
20
|
|
|
* Factory for all useful types of objects needed by the ODS Writer |
21
|
|
|
* |
22
|
|
|
* @package Box\Spout\Writer\ODS\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
|
48 |
|
public function __construct(EntityFactory $entityFactory) |
35
|
|
|
{ |
36
|
48 |
|
$this->entityFactory = $entityFactory; |
37
|
48 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param OptionsManagerInterface $optionsManager |
41
|
|
|
* @return WorkbookManager |
42
|
|
|
*/ |
43
|
43 |
|
public function createWorkbookManager(OptionsManagerInterface $optionsManager) |
44
|
|
|
{ |
45
|
43 |
|
$workbook = $this->entityFactory->createWorkbook(); |
46
|
|
|
|
47
|
43 |
|
$fileSystemHelper = $this->createFileSystemHelper($optionsManager); |
48
|
43 |
|
$fileSystemHelper->createBaseFilesAndFolders(); |
49
|
|
|
|
50
|
43 |
|
$styleManager = $this->createStyleManager($optionsManager); |
51
|
43 |
|
$worksheetManager = $this->createWorksheetManager(); |
52
|
|
|
|
53
|
43 |
|
return new WorkbookManager($workbook, $optionsManager, $worksheetManager, $styleManager, $fileSystemHelper, $this->entityFactory); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return WorksheetManager |
58
|
|
|
*/ |
59
|
43 |
|
private function createWorksheetManager() |
60
|
|
|
{ |
61
|
43 |
|
$stringsEscaper = $this->createStringsEscaper(); |
62
|
43 |
|
$stringsHelper = $this->createStringHelper(); |
63
|
|
|
|
64
|
43 |
|
return new WorksheetManager($stringsEscaper, $stringsHelper); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param OptionsManagerInterface $optionsManager |
69
|
|
|
* @return StyleManager |
70
|
|
|
*/ |
71
|
43 |
|
private function createStyleManager(OptionsManagerInterface $optionsManager) |
72
|
|
|
{ |
73
|
43 |
|
$styleRegistry = $this->createStyleRegistry($optionsManager); |
74
|
43 |
|
return new StyleManager($styleRegistry); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param OptionsManagerInterface $optionsManager |
79
|
|
|
* @return StyleRegistry |
80
|
|
|
*/ |
81
|
43 |
|
private function createStyleRegistry(OptionsManagerInterface $optionsManager) |
82
|
|
|
{ |
83
|
43 |
|
$defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE); |
84
|
43 |
|
return new StyleRegistry($defaultRowStyle); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param OptionsManagerInterface $optionsManager |
89
|
|
|
* @return FileSystemHelper |
90
|
|
|
*/ |
91
|
43 |
|
public function createFileSystemHelper(OptionsManagerInterface $optionsManager) |
92
|
|
|
{ |
93
|
43 |
|
$tempFolder = $optionsManager->getOption(Options::TEMP_FOLDER); |
94
|
43 |
|
$zipHelper = $this->createZipHelper(); |
95
|
|
|
|
96
|
43 |
|
return new FileSystemHelper($tempFolder, $zipHelper); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return ZipHelper |
101
|
|
|
*/ |
102
|
43 |
|
private function createZipHelper() |
103
|
|
|
{ |
104
|
43 |
|
return new ZipHelper(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return Escaper\ODS |
109
|
|
|
*/ |
110
|
43 |
|
private function createStringsEscaper() |
111
|
|
|
{ |
112
|
43 |
|
return Escaper\ODS::getInstance(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return StringHelper |
117
|
|
|
*/ |
118
|
43 |
|
private function createStringHelper() |
119
|
|
|
{ |
120
|
43 |
|
return new StringHelper(); |
121
|
|
|
} |
122
|
|
|
} |