1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader\XLSX\Creator; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface; |
6
|
|
|
use Box\Spout\Reader\Common\Entity\Options; |
7
|
|
|
use Box\Spout\Reader\Common\XMLProcessor; |
8
|
|
|
use Box\Spout\Reader\Wrapper\XMLReader; |
9
|
|
|
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager; |
10
|
|
|
use Box\Spout\Reader\XLSX\RowIterator; |
11
|
|
|
use Box\Spout\Reader\XLSX\Sheet; |
12
|
|
|
use Box\Spout\Reader\XLSX\SheetIterator; |
13
|
|
|
use MongoDB\Driver\Manager; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class EntityFactory |
17
|
|
|
* Factory to create entities |
18
|
|
|
*/ |
19
|
|
|
class EntityFactory implements EntityFactoryInterface |
20
|
|
|
{ |
21
|
|
|
/** @var HelperFactory */ |
22
|
|
|
private $helperFactory; |
23
|
|
|
|
24
|
|
|
/** @var ManagerFactory */ |
25
|
|
|
private $managerFactory; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param ManagerFactory $managerFactory |
29
|
|
|
* @param HelperFactory $helperFactory |
30
|
|
|
*/ |
31
|
79 |
|
public function __construct(ManagerFactory $managerFactory, HelperFactory $helperFactory) |
32
|
|
|
{ |
33
|
79 |
|
$this->managerFactory = $managerFactory; |
34
|
79 |
|
$this->helperFactory = $helperFactory; |
35
|
79 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $filePath Path of the file to be read |
39
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
40
|
|
|
* @param SharedStringsManager $sharedStringsManager Manages shared strings |
41
|
|
|
* @return SheetIterator |
42
|
|
|
*/ |
43
|
35 |
|
public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager) |
44
|
|
|
{ |
45
|
35 |
|
$sheetManager = $this->managerFactory->createSheetManager($filePath, $optionsManager, $sharedStringsManager, $this); |
46
|
|
|
|
47
|
35 |
|
return new SheetIterator($sheetManager); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $filePath Path of the XLSX file being read |
52
|
|
|
* @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml |
53
|
|
|
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based) |
54
|
|
|
* @param string $sheetName Name of the sheet |
55
|
|
|
* @param bool $isSheetActive Whether the sheet was defined as active |
56
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
57
|
|
|
* @param SharedStringsManager $sharedStringsManager Manages shared strings |
58
|
|
|
* @return Sheet |
59
|
|
|
*/ |
60
|
34 |
|
public function createSheet( |
61
|
|
|
$filePath, |
62
|
|
|
$sheetDataXMLFilePath, |
63
|
|
|
$sheetIndex, |
64
|
|
|
$sheetName, |
65
|
|
|
$isSheetActive, |
66
|
|
|
$optionsManager, |
67
|
|
|
$sharedStringsManager |
68
|
|
|
) { |
69
|
34 |
|
$rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager); |
70
|
|
|
|
71
|
34 |
|
return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $filePath Path of the XLSX file being read |
76
|
|
|
* @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml |
77
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
78
|
|
|
* @param SharedStringsManager $sharedStringsManager Manages shared strings |
79
|
|
|
* @return RowIterator |
80
|
|
|
*/ |
81
|
34 |
|
private function createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager) |
82
|
|
|
{ |
83
|
34 |
|
$xmlReader = $this->createXMLReader(); |
84
|
34 |
|
$xmlProcessor = $this->createXMLProcessor($xmlReader); |
85
|
|
|
|
86
|
34 |
|
$styleManager = $this->managerFactory->createStyleManager($filePath, $this); |
87
|
34 |
|
$shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES); |
88
|
34 |
|
$shouldUse1904Dates = $optionsManager->getOption(Options::SHOULD_USE_1904_DATES); |
89
|
|
|
|
90
|
34 |
|
$cellValueFormatter = $this->helperFactory->createCellValueFormatter( |
91
|
34 |
|
$sharedStringsManager, |
92
|
34 |
|
$styleManager, |
93
|
34 |
|
$shouldFormatDates, |
94
|
34 |
|
$shouldUse1904Dates |
95
|
|
|
); |
96
|
|
|
|
97
|
34 |
|
$shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS); |
98
|
|
|
|
99
|
34 |
|
return new RowIterator( |
100
|
34 |
|
$filePath, |
101
|
34 |
|
$sheetDataXMLFilePath, |
102
|
34 |
|
$shouldPreserveEmptyRows, |
103
|
34 |
|
$xmlReader, |
104
|
34 |
|
$xmlProcessor, |
105
|
34 |
|
$cellValueFormatter |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return \ZipArchive |
111
|
|
|
*/ |
112
|
37 |
|
public function createZipArchive() |
113
|
|
|
{ |
114
|
37 |
|
return new \ZipArchive(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return XMLReader |
119
|
|
|
*/ |
120
|
42 |
|
public function createXMLReader() |
121
|
|
|
{ |
122
|
42 |
|
return new XMLReader(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param $xmlReader |
127
|
|
|
* @return XMLProcessor |
128
|
|
|
*/ |
129
|
35 |
|
public function createXMLProcessor($xmlReader) |
130
|
|
|
{ |
131
|
35 |
|
return new XMLProcessor($xmlReader); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|