|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader; |
|
4
|
|
|
|
|
5
|
|
|
use Box\Spout\Common\Creator\HelperFactory; |
|
6
|
|
|
use Box\Spout\Common\Exception\UnsupportedTypeException; |
|
7
|
|
|
use Box\Spout\Common\Type; |
|
8
|
|
|
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class ReaderFactory |
|
12
|
|
|
* This factory is used to create readers, based on the type of the file to be read. |
|
13
|
|
|
* It supports CSV and XLSX formats. |
|
14
|
|
|
*/ |
|
15
|
|
|
class ReaderFactory |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* This creates an instance of the appropriate reader, given the type of the file to be read |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $readerType Type of the reader to instantiate |
|
21
|
|
|
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException |
|
22
|
|
|
* @return ReaderInterface |
|
23
|
|
|
*/ |
|
24
|
80 |
|
public static function create($readerType) |
|
25
|
|
|
{ |
|
26
|
|
|
switch ($readerType) { |
|
27
|
80 |
|
case Type::CSV: return self::getCSVReader(); |
|
28
|
79 |
|
case Type::XLSX: return self::getXLSXReader(); |
|
29
|
35 |
|
case Type::ODS: return self::getODSReader(); |
|
30
|
|
|
default: |
|
31
|
1 |
|
throw new UnsupportedTypeException('No readers supporting the given type: ' . $readerType); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return CSV\Reader |
|
37
|
|
|
*/ |
|
38
|
1 |
|
private static function getCSVReader() |
|
39
|
|
|
{ |
|
40
|
1 |
|
$optionsManager = new CSV\Manager\OptionsManager(); |
|
41
|
1 |
|
$helperFactory = new HelperFactory(); |
|
42
|
1 |
|
$entityFactory = new CSV\Creator\InternalEntityFactory($helperFactory); |
|
43
|
1 |
|
$globalFunctionsHelper = $helperFactory->createGlobalFunctionsHelper(); |
|
44
|
|
|
|
|
45
|
1 |
|
return new CSV\Reader($optionsManager, $globalFunctionsHelper, $entityFactory); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return XLSX\Reader |
|
50
|
|
|
*/ |
|
51
|
44 |
|
private static function getXLSXReader() |
|
52
|
|
|
{ |
|
53
|
44 |
|
$optionsManager = new XLSX\Manager\OptionsManager(); |
|
54
|
44 |
|
$helperFactory = new XLSX\Creator\HelperFactory(); |
|
55
|
44 |
|
$managerFactory = new XLSX\Creator\ManagerFactory($helperFactory, new CachingStrategyFactory()); |
|
56
|
44 |
|
$entityFactory = new XLSX\Creator\InternalEntityFactory($managerFactory, $helperFactory); |
|
57
|
44 |
|
$globalFunctionsHelper = $helperFactory->createGlobalFunctionsHelper(); |
|
58
|
|
|
|
|
59
|
44 |
|
return new XLSX\Reader($optionsManager, $globalFunctionsHelper, $entityFactory, $managerFactory); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return ODS\Reader |
|
64
|
|
|
*/ |
|
65
|
34 |
|
private static function getODSReader() |
|
66
|
|
|
{ |
|
67
|
34 |
|
$optionsManager = new ODS\Manager\OptionsManager(); |
|
68
|
34 |
|
$helperFactory = new ODS\Creator\HelperFactory(); |
|
69
|
34 |
|
$managerFactory = new ODS\Creator\ManagerFactory(); |
|
70
|
34 |
|
$entityFactory = new ODS\Creator\InternalEntityFactory($helperFactory, $managerFactory); |
|
71
|
34 |
|
$globalFunctionsHelper = $helperFactory->createGlobalFunctionsHelper(); |
|
72
|
|
|
|
|
73
|
34 |
|
return new ODS\Reader($optionsManager, $globalFunctionsHelper, $entityFactory); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|