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 | 72 | 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 | 30 | public function setPath($path) |
|
70 | |||
71 | /** |
||
72 | * Set the sheet number. |
||
73 | * |
||
74 | * @param int $sheet |
||
75 | * |
||
76 | * @return self |
||
77 | */ |
||
78 | 18 | public function setSheet($sheet) |
|
84 | |||
85 | /** |
||
86 | * Set the parser. |
||
87 | * |
||
88 | * @param \Arcanedev\LaravelExcel\Contracts\Parser $parser |
||
89 | * |
||
90 | * @return self |
||
91 | */ |
||
92 | 72 | public function setParser(ParserContract $parser) |
|
98 | |||
99 | /** |
||
100 | * Get the file type. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 42 | public function getType() |
|
108 | |||
109 | /** |
||
110 | * Set the reader options. |
||
111 | * |
||
112 | * @param array $options |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | 72 | 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 | 30 | public function load($path) |
|
138 | |||
139 | /** |
||
140 | * Get the parsed data for a single sheet. |
||
141 | * |
||
142 | * @param int $sheet |
||
143 | * |
||
144 | * @return \Illuminate\Support\Collection |
||
145 | */ |
||
146 | 18 | public function get($sheet = 1) |
|
156 | |||
157 | /** |
||
158 | * Get the parsed data for all sheets. |
||
159 | * |
||
160 | * @return \Illuminate\Support\Collection |
||
161 | */ |
||
162 | 12 | public function all() |
|
171 | |||
172 | /* ------------------------------------------------------------------------------------------------ |
||
173 | | Other Functions |
||
174 | | ------------------------------------------------------------------------------------------------ |
||
175 | */ |
||
176 | /** |
||
177 | * Create the reader instance. |
||
178 | */ |
||
179 | 30 | protected function create() |
|
184 | |||
185 | /** |
||
186 | * Load the reader options. |
||
187 | */ |
||
188 | abstract protected function loadOptions(); |
||
189 | |||
190 | /** |
||
191 | * Parse the rows of selected sheet. |
||
192 | * |
||
193 | * @return \Illuminate\Support\Collection |
||
194 | */ |
||
195 | 18 | protected function parseRows() |
|
209 | |||
210 | /** |
||
211 | * Parse all the rows. |
||
212 | * |
||
213 | * @return \Illuminate\Support\Collection |
||
214 | */ |
||
215 | 12 | protected function parseAllRows() |
|
231 | } |
||
232 |