1 | <?php namespace Arcanedev\LaravelExcel\Importers; |
||
14 | abstract class AbstractImporter implements ImporterContract |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Properties |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | /** @var string */ |
||
21 | protected $type; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $path = ''; |
||
25 | |||
26 | /** @var int */ |
||
27 | protected $sheet = 0; |
||
28 | |||
29 | /** @var \Arcanedev\LaravelExcel\Contracts\Parser */ |
||
30 | protected $parser; |
||
31 | |||
32 | /** @var \Box\Spout\Reader\ReaderInterface */ |
||
33 | protected $reader; |
||
34 | |||
35 | /** @var array */ |
||
36 | protected $options = []; |
||
37 | |||
38 | /* ------------------------------------------------------------------------------------------------ |
||
39 | | Constructor |
||
40 | | ------------------------------------------------------------------------------------------------ |
||
41 | */ |
||
42 | /** |
||
43 | * AbstractImporter constructor. |
||
44 | * |
||
45 | * @param array $options |
||
46 | */ |
||
47 | 42 | public function __construct(array $options = []) |
|
52 | |||
53 | /* ------------------------------------------------------------------------------------------------ |
||
54 | | Getters & Setters |
||
55 | | ------------------------------------------------------------------------------------------------ |
||
56 | */ |
||
57 | /** |
||
58 | * Set the path. |
||
59 | * |
||
60 | * @param string $path |
||
61 | * |
||
62 | * @return self |
||
63 | */ |
||
64 | 12 | public function setPath($path) |
|
70 | |||
71 | /** |
||
72 | * Set the sheet number. |
||
73 | * |
||
74 | * @param int $sheet |
||
75 | * |
||
76 | * @return self |
||
77 | */ |
||
78 | 12 | public function setSheet($sheet) |
|
84 | |||
85 | /** |
||
86 | * Set the parser. |
||
87 | * |
||
88 | * @param \Arcanedev\LaravelExcel\Contracts\Parser $parser |
||
89 | * |
||
90 | * @return self |
||
91 | */ |
||
92 | 42 | public function setParser(ParserContract $parser) |
|
98 | |||
99 | /** |
||
100 | * Get the file type. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 30 | public function getType() |
|
108 | |||
109 | /** |
||
110 | * Set the reader options. |
||
111 | * |
||
112 | * @param array $options |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | 42 | public function setOptions(array $options) |
|
122 | |||
123 | /* ------------------------------------------------------------------------------------------------ |
||
124 | | Main Functions |
||
125 | | ------------------------------------------------------------------------------------------------ |
||
126 | */ |
||
127 | /** |
||
128 | * Load the file. |
||
129 | * |
||
130 | * @param string $path |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | 12 | public function load($path) |
|
138 | |||
139 | /** |
||
140 | * Get the parsed data. |
||
141 | * |
||
142 | * @return \Illuminate\Support\Collection |
||
143 | */ |
||
144 | 12 | public function get() |
|
153 | |||
154 | /* ------------------------------------------------------------------------------------------------ |
||
155 | | Other Functions |
||
156 | | ------------------------------------------------------------------------------------------------ |
||
157 | */ |
||
158 | /** |
||
159 | * Create the reader instance. |
||
160 | */ |
||
161 | 12 | protected function create() |
|
166 | |||
167 | /** |
||
168 | * Load the reader options. |
||
169 | */ |
||
170 | abstract protected function loadOptions(); |
||
171 | |||
172 | /** |
||
173 | * Parse the rows. |
||
174 | * |
||
175 | * @return \Illuminate\Support\Collection |
||
176 | */ |
||
177 | 12 | protected function parseRows() |
|
193 | } |
||
194 |