1 | <?php namespace Arcanedev\LaravelExcel\Importers; |
||
15 | abstract class AbstractImporter implements ImporterContract |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Traits |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | use WithOptions; |
||
23 | |||
24 | /* ----------------------------------------------------------------- |
||
25 | | Properties |
||
26 | | ----------------------------------------------------------------- |
||
27 | */ |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $type; |
||
31 | |||
32 | /** @var string */ |
||
33 | protected $path = ''; |
||
34 | |||
35 | /** @var int */ |
||
36 | protected $sheet = 0; |
||
37 | |||
38 | /** @var \Arcanedev\LaravelExcel\Contracts\Parser */ |
||
39 | protected $parser; |
||
40 | |||
41 | /** @var \Box\Spout\Reader\ReaderInterface */ |
||
42 | protected $reader; |
||
43 | |||
44 | /* ----------------------------------------------------------------- |
||
45 | | Constructor |
||
46 | | ----------------------------------------------------------------- |
||
47 | */ |
||
48 | |||
49 | /** |
||
50 | * AbstractImporter constructor. |
||
51 | * |
||
52 | * @param array $options |
||
53 | */ |
||
54 | 57 | public function __construct(array $options = []) |
|
59 | |||
60 | /* ----------------------------------------------------------------- |
||
61 | | Getters & Setters |
||
62 | | ----------------------------------------------------------------- |
||
63 | */ |
||
64 | |||
65 | /** |
||
66 | * Set the path. |
||
67 | * |
||
68 | * @param string $path |
||
69 | * |
||
70 | * @return self |
||
71 | */ |
||
72 | 18 | public function setPath($path) |
|
78 | |||
79 | /** |
||
80 | * Set the sheet number. |
||
81 | * |
||
82 | * @param int $sheet |
||
83 | * |
||
84 | * @return self |
||
85 | */ |
||
86 | 9 | public function setSheet($sheet) |
|
92 | |||
93 | /** |
||
94 | * Set the parser. |
||
95 | * |
||
96 | * @param \Arcanedev\LaravelExcel\Contracts\Parser $parser |
||
97 | * |
||
98 | * @return self |
||
99 | */ |
||
100 | 57 | public function setParser(ParserContract $parser) |
|
106 | |||
107 | /** |
||
108 | * Get the file type. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 21 | public function getType() |
|
116 | |||
117 | /* ----------------------------------------------------------------- |
||
118 | | Main Methods |
||
119 | | ----------------------------------------------------------------- |
||
120 | */ |
||
121 | |||
122 | /** |
||
123 | * Load the file. |
||
124 | * |
||
125 | * @param string $path |
||
126 | * |
||
127 | * @return self |
||
128 | */ |
||
129 | 18 | public function load($path) |
|
133 | |||
134 | /** |
||
135 | * Get the parsed data for a single sheet. |
||
136 | * |
||
137 | * @param int $sheet |
||
138 | * |
||
139 | * @return \Illuminate\Support\Collection |
||
140 | */ |
||
141 | 9 | public function get($sheet = 1) |
|
151 | |||
152 | /** |
||
153 | * Get the parsed data for all sheets. |
||
154 | * |
||
155 | * @return \Illuminate\Support\Collection |
||
156 | */ |
||
157 | 9 | public function all() |
|
166 | |||
167 | /* ----------------------------------------------------------------- |
||
168 | | Other Methods |
||
169 | | ----------------------------------------------------------------- |
||
170 | */ |
||
171 | |||
172 | /** |
||
173 | * Create the reader instance. |
||
174 | */ |
||
175 | 18 | protected function create() |
|
180 | |||
181 | /** |
||
182 | * Load the reader options. |
||
183 | */ |
||
184 | abstract protected function loadOptions(); |
||
185 | |||
186 | /** |
||
187 | * Parse the rows of selected sheet. |
||
188 | * |
||
189 | * @return \Illuminate\Support\Collection |
||
190 | */ |
||
191 | 9 | protected function parseRows() |
|
205 | |||
206 | /** |
||
207 | * Parse all the rows. |
||
208 | * |
||
209 | * @return \Illuminate\Support\Collection |
||
210 | */ |
||
211 | 9 | protected function parseAllRows() |
|
227 | } |
||
228 |