1 | <?php |
||
8 | abstract class Base |
||
9 | { |
||
10 | protected $file; |
||
11 | protected $fields; |
||
12 | protected $filePath; |
||
13 | protected $fileHandle; |
||
14 | |||
15 | /** |
||
16 | * Base constructor. |
||
17 | * @param $filePath |
||
18 | * |
||
19 | * @throws \Dyrynda\Artisan\Exceptions\ImportFileException |
||
20 | */ |
||
21 | 1 | public function __construct($filePath) |
|
22 | { |
||
23 | 1 | $this->filePath = $filePath; |
|
24 | |||
25 | 1 | $this->file = new SplFileInfo($filePath); |
|
26 | |||
27 | 1 | if (! $this->file->getExtension()) { |
|
28 | throw ImportFileException::noExtension(); |
||
29 | } |
||
30 | |||
31 | 1 | if (! $this->file->isFile()) { |
|
32 | 1 | throw ImportFileException::notExist($filePath); |
|
33 | } |
||
34 | |||
35 | $this->fileHandle = $this->file->openFile(); |
||
36 | |||
37 | $this->validateSyntax(); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Checks file for valid syntax |
||
42 | * |
||
43 | * @throws \Dyrynda\Artisan\Exceptions\ImportFileException |
||
44 | */ |
||
45 | abstract protected function validateSyntax(); |
||
46 | } |
||
47 |