1 | <?php |
||
19 | class TextFileLoader |
||
20 | { |
||
21 | /* |
||
22 | * @var FileLocation |
||
23 | */ |
||
24 | private $fileLocation; |
||
25 | |||
26 | /** |
||
27 | * @var FileContent |
||
28 | */ |
||
29 | private $rawContent; |
||
30 | |||
31 | /** |
||
32 | * @var TextFile |
||
33 | */ |
||
34 | private $file; |
||
35 | |||
36 | /** |
||
37 | * @var TextFileValidator |
||
38 | */ |
||
39 | private $validator; |
||
40 | |||
41 | /** |
||
42 | * @param FileLocation $fileLocation |
||
43 | */ |
||
44 | 1 | public function __construct(FileLocation $fileLocation) |
|
48 | |||
49 | /** |
||
50 | * Load the file to memory |
||
51 | * |
||
52 | * @throws InvalidFileLocationException |
||
53 | * @throws InvalidFileTypeException |
||
54 | * @return TextFile The text file itself |
||
55 | */ |
||
56 | 3 | public function loadFile() |
|
63 | |||
64 | /** |
||
65 | * @return FileContent |
||
66 | */ |
||
67 | 1 | protected function loadFileFromOS() |
|
68 | { |
||
69 | 1 | return new FileContent(new Stringy(file_get_contents($this->fileLocation->getValue()))); |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return TextFile |
||
74 | */ |
||
75 | 1 | protected function createFileObject() |
|
76 | { |
||
77 | 1 | $parser = new TextContentParser($this->rawContent); |
|
78 | 1 | return new TextFile($this->fileLocation, $this->rawContent, $parser->parse()); |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * @throws InvalidFileLocationException |
||
83 | * @throws InvalidFileTypeException |
||
84 | * @return bool |
||
85 | */ |
||
86 | 3 | protected function validateFile() |
|
87 | { |
||
88 | 3 | $this->getValidator()->validate(); |
|
89 | 1 | } |
|
90 | |||
91 | /** |
||
92 | * @return TextFileValidator |
||
93 | */ |
||
94 | protected function getValidator() |
||
101 | } |
||
102 |