1 | <?php namespace Arcanedev\LogViewer\Utilities; |
||
13 | class Filesystem implements FilesystemContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * The filesystem instance. |
||
22 | * |
||
23 | * @var \Illuminate\Filesystem\Filesystem |
||
24 | */ |
||
25 | protected $filesystem; |
||
26 | |||
27 | /** |
||
28 | * The base storage path. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $storagePath; |
||
33 | |||
34 | /** |
||
35 | * The log files prefix pattern. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $prefixPattern; |
||
40 | |||
41 | /** |
||
42 | * The log files date pattern. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $datePattern; |
||
47 | |||
48 | /** |
||
49 | * The log files extension. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $extension; |
||
54 | |||
55 | /* ----------------------------------------------------------------- |
||
56 | | Constructor |
||
57 | | ----------------------------------------------------------------- |
||
58 | */ |
||
59 | |||
60 | /** |
||
61 | * Filesystem constructor. |
||
62 | * |
||
63 | * @param \Illuminate\Filesystem\Filesystem $files |
||
64 | * @param string $storagePath |
||
65 | */ |
||
66 | 369 | public function __construct(IlluminateFilesystem $files, $storagePath) |
|
72 | |||
73 | /* ----------------------------------------------------------------- |
||
74 | | Getters & Setters |
||
75 | | ----------------------------------------------------------------- |
||
76 | */ |
||
77 | |||
78 | /** |
||
79 | * Get the files instance. |
||
80 | * |
||
81 | * @return \Illuminate\Filesystem\Filesystem |
||
82 | */ |
||
83 | 3 | public function getInstance() |
|
87 | |||
88 | /** |
||
89 | * Set the log storage path. |
||
90 | * |
||
91 | * @param string $storagePath |
||
92 | * |
||
93 | * @return self |
||
94 | */ |
||
95 | 369 | public function setPath($storagePath) |
|
101 | |||
102 | /** |
||
103 | * Get the log pattern. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | 213 | public function getPattern() |
|
111 | |||
112 | /** |
||
113 | * Set the log pattern. |
||
114 | * |
||
115 | * @param string $date |
||
116 | * @param string $prefix |
||
117 | * @param string $extension |
||
118 | * |
||
119 | * @return self |
||
120 | */ |
||
121 | 369 | public function setPattern( |
|
132 | |||
133 | /** |
||
134 | * Set the log date pattern. |
||
135 | * |
||
136 | * @param string $datePattern |
||
137 | * |
||
138 | * @return self |
||
139 | */ |
||
140 | 369 | public function setDatePattern($datePattern) |
|
146 | |||
147 | /** |
||
148 | * Set the log prefix pattern. |
||
149 | * |
||
150 | * @param string $prefixPattern |
||
151 | * |
||
152 | * @return self |
||
153 | */ |
||
154 | 369 | public function setPrefixPattern($prefixPattern) |
|
160 | |||
161 | /** |
||
162 | * Set the log extension. |
||
163 | * |
||
164 | * @param string $extension |
||
165 | * |
||
166 | * @return self |
||
167 | */ |
||
168 | 369 | public function setExtension($extension) |
|
174 | |||
175 | /* ----------------------------------------------------------------- |
||
176 | | Main Methods |
||
177 | | ----------------------------------------------------------------- |
||
178 | */ |
||
179 | |||
180 | /** |
||
181 | * Get all log files. |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | 21 | public function all() |
|
189 | |||
190 | /** |
||
191 | * Get all valid log files. |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | 204 | public function logs() |
|
199 | |||
200 | /** |
||
201 | * List the log files (Only dates). |
||
202 | * |
||
203 | * @param bool $withPaths |
||
204 | * |
||
205 | * @return array |
||
206 | */ |
||
207 | 189 | public function dates($withPaths = false) |
|
218 | |||
219 | /** |
||
220 | * Read the log. |
||
221 | * |
||
222 | * @param string $date |
||
223 | * |
||
224 | * @return string |
||
225 | * |
||
226 | * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException |
||
227 | */ |
||
228 | 252 | public function read($date) |
|
241 | |||
242 | /** |
||
243 | * Delete the log. |
||
244 | * |
||
245 | * @param string $date |
||
246 | * |
||
247 | * @return bool |
||
248 | * |
||
249 | * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException |
||
250 | */ |
||
251 | 15 | public function delete($date) |
|
263 | |||
264 | /** |
||
265 | * Clear the log files. |
||
266 | * |
||
267 | * @return bool |
||
268 | */ |
||
269 | 3 | public function clear() |
|
275 | |||
276 | /** |
||
277 | * Get the log file path. |
||
278 | * |
||
279 | * @param string $date |
||
280 | * |
||
281 | * @return string |
||
282 | */ |
||
283 | 69 | public function path($date) |
|
287 | |||
288 | /* ----------------------------------------------------------------- |
||
289 | | Other Methods |
||
290 | | ----------------------------------------------------------------- |
||
291 | */ |
||
292 | |||
293 | /** |
||
294 | * Get all files. |
||
295 | * |
||
296 | * @param string $pattern |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | 225 | private function getFiles($pattern) |
|
308 | |||
309 | /** |
||
310 | * Get the log file path. |
||
311 | * |
||
312 | * @param string $date |
||
313 | * |
||
314 | * @return string |
||
315 | * |
||
316 | * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException |
||
317 | */ |
||
318 | 270 | private function getLogPath($date) |
|
328 | |||
329 | /** |
||
330 | * Extract dates from files. |
||
331 | * |
||
332 | * @param array $files |
||
333 | * |
||
334 | * @return array |
||
335 | */ |
||
336 | 189 | private function extractDates(array $files) |
|
342 | } |
||
343 |