1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader\ODS\Creator; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface; |
6
|
|
|
use Box\Spout\Reader\Common\Entity\Options; |
7
|
|
|
use Box\Spout\Reader\Common\XMLProcessor; |
8
|
|
|
use Box\Spout\Reader\ODS\RowIterator; |
9
|
|
|
use Box\Spout\Reader\ODS\Sheet; |
10
|
|
|
use Box\Spout\Reader\ODS\SheetIterator; |
11
|
|
|
use Box\Spout\Reader\Wrapper\XMLReader; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class EntityFactory |
15
|
|
|
* Factory to create entities |
16
|
|
|
*/ |
17
|
|
|
class InternalEntityFactory implements InternalEntityFactoryInterface |
18
|
|
|
{ |
19
|
|
|
/** @var HelperFactory */ |
20
|
|
|
private $helperFactory; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param HelperFactory $helperFactory |
24
|
|
|
*/ |
25
|
34 |
|
public function __construct(HelperFactory $helperFactory) |
26
|
|
|
{ |
27
|
34 |
|
$this->helperFactory = $helperFactory; |
28
|
34 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $filePath Path of the file to be read |
32
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
33
|
|
|
* @return SheetIterator |
34
|
|
|
*/ |
35
|
31 |
|
public function createSheetIterator($filePath, $optionsManager) |
36
|
|
|
{ |
37
|
31 |
|
$escaper = $this->helperFactory->createStringsEscaper(); |
38
|
31 |
|
$settingsHelper = $this->helperFactory->createSettingsHelper($this); |
39
|
|
|
|
40
|
31 |
|
return new SheetIterator($filePath, $optionsManager, $escaper, $settingsHelper, $this); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param XMLReader $xmlReader XML Reader |
45
|
|
|
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based) |
46
|
|
|
* @param string $sheetName Name of the sheet |
47
|
|
|
* @param bool $isSheetActive Whether the sheet was defined as active |
48
|
|
|
* @param bool $isSheetVisible Whether the sheet is visible |
49
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
50
|
|
|
* @return Sheet |
51
|
|
|
*/ |
52
|
29 |
|
public function createSheet($xmlReader, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible, $optionsManager) |
53
|
|
|
{ |
54
|
29 |
|
$rowIterator = $this->createRowIterator($xmlReader, $optionsManager); |
55
|
|
|
|
56
|
29 |
|
return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param XMLReader $xmlReader XML Reader |
61
|
|
|
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager |
62
|
|
|
* @return RowIterator |
63
|
|
|
*/ |
64
|
29 |
|
private function createRowIterator($xmlReader, $optionsManager) |
65
|
|
|
{ |
66
|
29 |
|
$shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES); |
67
|
29 |
|
$cellValueFormatter = $this->helperFactory->createCellValueFormatter($shouldFormatDates); |
68
|
29 |
|
$xmlProcessor = $this->createXMLProcessor($xmlReader); |
69
|
|
|
|
70
|
29 |
|
return new RowIterator($xmlReader, $optionsManager, $cellValueFormatter, $xmlProcessor); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return XMLReader |
75
|
|
|
*/ |
76
|
31 |
|
public function createXMLReader() |
77
|
|
|
{ |
78
|
31 |
|
return new XMLReader(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $xmlReader |
83
|
|
|
* @return XMLProcessor |
84
|
|
|
*/ |
85
|
29 |
|
private function createXMLProcessor($xmlReader) |
86
|
|
|
{ |
87
|
29 |
|
return new XMLProcessor($xmlReader); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return \ZipArchive |
92
|
|
|
*/ |
93
|
31 |
|
public function createZipArchive() |
94
|
|
|
{ |
95
|
31 |
|
return new \ZipArchive(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|