1 | <?php namespace Arcanedev\LaravelExcel\Importers; |
||
17 | abstract class AbstractImporter implements ImporterContract |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Traits |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | use WithOptions; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Properties |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | |||
31 | /** @var string */ |
||
32 | protected $type; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $path = ''; |
||
36 | |||
37 | /** @var \Arcanedev\LaravelExcel\Contracts\Parser */ |
||
38 | protected $parser; |
||
39 | |||
40 | /** @var \Box\Spout\Reader\ReaderInterface */ |
||
41 | protected $reader; |
||
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Constructor |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * AbstractImporter constructor. |
||
50 | * |
||
51 | * @param array $options |
||
52 | */ |
||
53 | 57 | public function __construct(array $options = []) |
|
58 | |||
59 | /* ----------------------------------------------------------------- |
||
60 | | Getters & Setters |
||
61 | | ----------------------------------------------------------------- |
||
62 | */ |
||
63 | |||
64 | /** |
||
65 | * Set the path. |
||
66 | * |
||
67 | * @param string $path |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | 18 | public function setPath($path) |
|
77 | |||
78 | /** |
||
79 | * Set the parser. |
||
80 | * |
||
81 | * @param \Arcanedev\LaravelExcel\Contracts\Parser $parser |
||
82 | * |
||
83 | * @return self |
||
84 | */ |
||
85 | 57 | public function setParser(ParserContract $parser) |
|
91 | |||
92 | /** |
||
93 | * Get the file type. |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 21 | public function getType() |
|
101 | |||
102 | /* ----------------------------------------------------------------- |
||
103 | | Main Methods |
||
104 | | ----------------------------------------------------------------- |
||
105 | */ |
||
106 | |||
107 | /** |
||
108 | * Load the file. |
||
109 | * |
||
110 | * @param string $path |
||
111 | * |
||
112 | * @return self |
||
113 | */ |
||
114 | 18 | public function load($path) |
|
118 | |||
119 | /** |
||
120 | * Get the parsed data for a single sheet. |
||
121 | * |
||
122 | * @param int|string $sheet |
||
123 | * |
||
124 | * @return \Illuminate\Support\Collection |
||
125 | */ |
||
126 | 18 | public function get($sheet = 1) |
|
135 | |||
136 | /** |
||
137 | * Get the parsed data for all sheets. |
||
138 | * |
||
139 | * @return \Illuminate\Support\Collection |
||
140 | */ |
||
141 | 9 | public function all() |
|
145 | |||
146 | /* ----------------------------------------------------------------- |
||
147 | | Other Methods |
||
148 | | ----------------------------------------------------------------- |
||
149 | */ |
||
150 | |||
151 | /** |
||
152 | * Create the reader instance. |
||
153 | */ |
||
154 | 18 | protected function create() |
|
159 | |||
160 | /** |
||
161 | * Load the reader options. |
||
162 | */ |
||
163 | abstract protected function loadOptions(); |
||
164 | |||
165 | /** |
||
166 | * Parse the rows of selected sheet. |
||
167 | * |
||
168 | * @param int|string $sheetIndex |
||
169 | * |
||
170 | * @return \Illuminate\Support\Collection |
||
171 | */ |
||
172 | 18 | protected function parseRows($sheetIndex) |
|
196 | |||
197 | /** |
||
198 | * Create a new collection object. |
||
199 | * |
||
200 | * @return \Illuminate\Support\Collection |
||
201 | */ |
||
202 | 18 | protected function newCollection() |
|
206 | } |
||
207 |