|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader\ODS\Creator; |
|
4
|
|
|
|
|
5
|
|
|
use Box\Spout\Common\Entity\Cell; |
|
6
|
|
|
use Box\Spout\Common\Entity\Row; |
|
7
|
|
|
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface; |
|
8
|
|
|
use Box\Spout\Reader\Common\Entity\Options; |
|
9
|
|
|
use Box\Spout\Reader\Common\XMLProcessor; |
|
10
|
|
|
use Box\Spout\Reader\ODS\RowIterator; |
|
11
|
|
|
use Box\Spout\Reader\ODS\Sheet; |
|
12
|
|
|
use Box\Spout\Reader\ODS\SheetIterator; |
|
13
|
|
|
use Box\Spout\Reader\Wrapper\XMLReader; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class EntityFactory |
|
17
|
|
|
* Factory to create entities |
|
18
|
|
|
*/ |
|
19
|
|
|
class InternalEntityFactory implements InternalEntityFactoryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var HelperFactory */ |
|
22
|
|
|
private $helperFactory; |
|
23
|
|
|
|
|
24
|
|
|
/** @var ManagerFactory */ |
|
25
|
|
|
private $managerFactory; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param HelperFactory $helperFactory |
|
29
|
|
|
* @param ManagerFactory $managerFactory |
|
30
|
|
|
*/ |
|
31
|
36 |
|
public function __construct(HelperFactory $helperFactory, ManagerFactory $managerFactory) |
|
32
|
|
|
{ |
|
33
|
36 |
|
$this->helperFactory = $helperFactory; |
|
34
|
36 |
|
$this->managerFactory = $managerFactory; |
|
35
|
36 |
|
} |
|
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
|
|
|
* @return SheetIterator |
|
41
|
|
|
*/ |
|
42
|
31 |
|
public function createSheetIterator($filePath, $optionsManager) |
|
43
|
|
|
{ |
|
44
|
31 |
|
$escaper = $this->helperFactory->createStringsEscaper(); |
|
45
|
31 |
|
$settingsHelper = $this->helperFactory->createSettingsHelper($this); |
|
46
|
|
|
|
|
47
|
31 |
|
return new SheetIterator($filePath, $optionsManager, $escaper, $settingsHelper, $this); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param XMLReader $xmlReader XML Reader |
|
52
|
|
|
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based) |
|
53
|
|
|
* @param string $sheetName Name of the sheet |
|
54
|
|
|
* @param bool $isSheetActive Whether the sheet was defined as active |
|
55
|
|
|
* @param bool $isSheetVisible Whether the sheet is visible |
|
56
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
|
57
|
|
|
* @return Sheet |
|
58
|
|
|
*/ |
|
59
|
29 |
|
public function createSheet($xmlReader, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible, $optionsManager) |
|
60
|
|
|
{ |
|
61
|
29 |
|
$rowIterator = $this->createRowIterator($xmlReader, $optionsManager); |
|
62
|
|
|
|
|
63
|
29 |
|
return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param XMLReader $xmlReader XML Reader |
|
68
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
|
69
|
|
|
* @return RowIterator |
|
70
|
|
|
*/ |
|
71
|
29 |
|
private function createRowIterator($xmlReader, $optionsManager) |
|
72
|
|
|
{ |
|
73
|
29 |
|
$shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES); |
|
74
|
29 |
|
$cellValueFormatter = $this->helperFactory->createCellValueFormatter($shouldFormatDates); |
|
75
|
29 |
|
$xmlProcessor = $this->createXMLProcessor($xmlReader); |
|
76
|
29 |
|
$rowManager = $this->managerFactory->createRowManager($this); |
|
77
|
|
|
|
|
78
|
29 |
|
return new RowIterator($xmlReader, $optionsManager, $cellValueFormatter, $xmlProcessor, $rowManager, $this); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param Cell[] $cells |
|
83
|
|
|
* @return Row |
|
84
|
|
|
*/ |
|
85
|
26 |
|
public function createRow(array $cells = []) |
|
86
|
|
|
{ |
|
87
|
26 |
|
return new Row($cells, null); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param mixed $cellValue |
|
92
|
|
|
* @return Cell |
|
93
|
|
|
*/ |
|
94
|
26 |
|
public function createCell($cellValue) |
|
95
|
|
|
{ |
|
96
|
26 |
|
return new Cell($cellValue); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return XMLReader |
|
101
|
|
|
*/ |
|
102
|
31 |
|
public function createXMLReader() |
|
103
|
|
|
{ |
|
104
|
31 |
|
return new XMLReader(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param $xmlReader |
|
109
|
|
|
* @return XMLProcessor |
|
110
|
|
|
*/ |
|
111
|
29 |
|
private function createXMLProcessor($xmlReader) |
|
112
|
|
|
{ |
|
113
|
29 |
|
return new XMLProcessor($xmlReader); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return \ZipArchive |
|
118
|
|
|
*/ |
|
119
|
31 |
|
public function createZipArchive() |
|
120
|
|
|
{ |
|
121
|
31 |
|
return new \ZipArchive(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|