1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader\CSV\Creator; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Common\Creator\HelperFactory; |
6
|
|
|
use Box\Spout\Common\Helper\GlobalFunctionsHelper; |
7
|
|
|
use Box\Spout\Common\Manager\OptionsManagerInterface; |
8
|
|
|
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface; |
9
|
|
|
use Box\Spout\Reader\Common\Entity\Cell; |
10
|
|
|
use Box\Spout\Reader\Common\Entity\Row; |
11
|
|
|
use Box\Spout\Reader\CSV\RowIterator; |
12
|
|
|
use Box\Spout\Reader\CSV\Sheet; |
13
|
|
|
use Box\Spout\Reader\CSV\SheetIterator; |
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
|
|
|
/** |
25
|
|
|
* @param HelperFactory $helperFactory |
26
|
|
|
*/ |
27
|
32 |
|
public function __construct(HelperFactory $helperFactory) |
28
|
|
|
{ |
29
|
32 |
|
$this->helperFactory = $helperFactory; |
30
|
32 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param resource $filePointer Pointer to the CSV file to read |
34
|
|
|
* @param OptionsManagerInterface $optionsManager |
35
|
|
|
* @param GlobalFunctionsHelper $globalFunctionsHelper |
36
|
|
|
* @return SheetIterator |
37
|
|
|
*/ |
38
|
27 |
|
public function createSheetIterator($filePointer, $optionsManager, $globalFunctionsHelper) |
39
|
|
|
{ |
40
|
27 |
|
$rowIterator = $this->createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper); |
41
|
27 |
|
$sheet = $this->createSheet($rowIterator); |
42
|
|
|
|
43
|
27 |
|
return new SheetIterator($sheet); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param RowIterator $rowIterator |
48
|
|
|
* @return Sheet |
49
|
|
|
*/ |
50
|
27 |
|
private function createSheet($rowIterator) |
51
|
|
|
{ |
52
|
27 |
|
return new Sheet($rowIterator); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param resource $filePointer Pointer to the CSV file to read |
57
|
|
|
* @param OptionsManagerInterface $optionsManager |
58
|
|
|
* @param GlobalFunctionsHelper $globalFunctionsHelper |
59
|
|
|
* @return RowIterator |
60
|
|
|
*/ |
61
|
27 |
|
private function createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper) |
62
|
|
|
{ |
63
|
27 |
|
$encodingHelper = $this->helperFactory->createEncodingHelper($globalFunctionsHelper); |
64
|
|
|
|
65
|
27 |
|
return new RowIterator($filePointer, $optionsManager, $encodingHelper, $this, $globalFunctionsHelper); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Cell[] $cells |
70
|
|
|
* @return Row |
71
|
|
|
*/ |
72
|
24 |
|
public function createRow(array $cells = []) |
73
|
|
|
{ |
74
|
24 |
|
return new Row($cells); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param mixed $cellValue |
79
|
|
|
* @return Cell |
80
|
|
|
*/ |
81
|
24 |
|
public function createCell($cellValue) |
82
|
|
|
{ |
83
|
24 |
|
return new Cell($cellValue); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param array $cellValues |
88
|
|
|
* @return Row |
89
|
|
|
*/ |
90
|
|
|
public function createRowFromArray(array $cellValues = []) |
91
|
|
|
{ |
92
|
24 |
|
$cells = array_map(function ($cellValue) { |
93
|
24 |
|
return $this->createCell($cellValue); |
94
|
24 |
|
}, $cellValues); |
95
|
|
|
|
96
|
|
|
return $this->createRow($cells); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|