1 | <?php namespace Arcanedev\LogViewer\Utilities; |
||
13 | class Filesystem implements FilesystemInterface |
||
14 | { |
||
15 | /* ------------------------------------------------------------------------------------------------ |
||
16 | | Properties |
||
17 | | ------------------------------------------------------------------------------------------------ |
||
18 | */ |
||
19 | /** |
||
20 | * The filesystem instance. |
||
21 | * |
||
22 | * @var \Illuminate\Filesystem\Filesystem |
||
23 | */ |
||
24 | protected $filesystem; |
||
25 | |||
26 | /** |
||
27 | * The base storage path. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $storagePath; |
||
32 | |||
33 | /** |
||
34 | * The log files prefix pattern. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $prefixPattern; |
||
39 | |||
40 | /** |
||
41 | * The log files date pattern. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $datePattern; |
||
46 | |||
47 | /** |
||
48 | * The log files extension. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $extension; |
||
53 | |||
54 | /* ------------------------------------------------------------------------------------------------ |
||
55 | | Constructor |
||
56 | | ------------------------------------------------------------------------------------------------ |
||
57 | */ |
||
58 | /** |
||
59 | * Create a new instance. |
||
60 | * |
||
61 | * @param \Illuminate\Filesystem\Filesystem $files |
||
62 | * @param string $storagePath |
||
63 | */ |
||
64 | 1368 | public function __construct(IlluminateFilesystem $files, $storagePath) |
|
70 | |||
71 | /* ------------------------------------------------------------------------------------------------ |
||
72 | | Getters & Setters |
||
73 | | ------------------------------------------------------------------------------------------------ |
||
74 | */ |
||
75 | /** |
||
76 | * Get the files instance. |
||
77 | * |
||
78 | * @return \Illuminate\Filesystem\Filesystem |
||
79 | */ |
||
80 | 12 | public function getInstance() |
|
84 | |||
85 | /** |
||
86 | * Set the log storage path. |
||
87 | * |
||
88 | * @param string $storagePath |
||
89 | * |
||
90 | * @return self |
||
91 | */ |
||
92 | 1368 | public function setPath($storagePath) |
|
98 | |||
99 | /** |
||
100 | * Get the log pattern. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 816 | public function getPattern() |
|
108 | |||
109 | /** |
||
110 | * Set the log pattern. |
||
111 | * |
||
112 | * @param string $date |
||
113 | * @param string $prefix |
||
114 | * @param string $extension |
||
115 | * |
||
116 | * @return self |
||
117 | */ |
||
118 | 1368 | public function setPattern( |
|
129 | |||
130 | /** |
||
131 | * Set the log date pattern. |
||
132 | * |
||
133 | * @param string $datePattern |
||
134 | * |
||
135 | * @return self |
||
136 | */ |
||
137 | 1368 | public function setDatePattern($datePattern) |
|
143 | |||
144 | /** |
||
145 | * Set the log prefix pattern. |
||
146 | * |
||
147 | * @param string $prefixPattern |
||
148 | * |
||
149 | * @return self |
||
150 | */ |
||
151 | 1368 | public function setPrefixPattern($prefixPattern) |
|
157 | |||
158 | /** |
||
159 | * Set the log extension. |
||
160 | * |
||
161 | * @param string $extension |
||
162 | * |
||
163 | * @return self |
||
164 | */ |
||
165 | 1368 | public function setExtension($extension) |
|
171 | |||
172 | /* ------------------------------------------------------------------------------------------------ |
||
173 | | Main Functions |
||
174 | | ------------------------------------------------------------------------------------------------ |
||
175 | */ |
||
176 | /** |
||
177 | * Get all log files. |
||
178 | * |
||
179 | * @return array |
||
180 | */ |
||
181 | 84 | public function all() |
|
185 | |||
186 | /** |
||
187 | * Get all valid log files. |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | 780 | public function logs() |
|
195 | |||
196 | /** |
||
197 | * List the log files (Only dates). |
||
198 | * |
||
199 | * @param bool|false $withPaths |
||
200 | * |
||
201 | * @return array |
||
202 | */ |
||
203 | 720 | public function dates($withPaths = false) |
|
214 | |||
215 | /** |
||
216 | * Read the log. |
||
217 | * |
||
218 | * @param string $date |
||
219 | * |
||
220 | * @return string |
||
221 | * |
||
222 | * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException |
||
223 | */ |
||
224 | 900 | public function read($date) |
|
235 | |||
236 | /** |
||
237 | * Delete the log. |
||
238 | * |
||
239 | * @param string $date |
||
240 | * |
||
241 | * @return bool |
||
242 | * |
||
243 | * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException |
||
244 | */ |
||
245 | 60 | public function delete($date) |
|
259 | |||
260 | /** |
||
261 | * Get the log file path. |
||
262 | * |
||
263 | * @param string $date |
||
264 | * |
||
265 | * @return string |
||
266 | * |
||
267 | * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException |
||
268 | */ |
||
269 | 204 | public function path($date) |
|
273 | |||
274 | /* ------------------------------------------------------------------------------------------------ |
||
275 | | Other Functions |
||
276 | | ------------------------------------------------------------------------------------------------ |
||
277 | */ |
||
278 | /** |
||
279 | * Get all files. |
||
280 | * |
||
281 | * @param string $pattern |
||
282 | * |
||
283 | * @return array |
||
284 | */ |
||
285 | 864 | private function getFiles($pattern) |
|
294 | |||
295 | /** |
||
296 | * Get the log file path. |
||
297 | * |
||
298 | * @param string $date |
||
299 | * |
||
300 | * @return string |
||
301 | * |
||
302 | * @throws \Arcanedev\LogViewer\Exceptions\FilesystemException |
||
303 | */ |
||
304 | 972 | private function getLogPath($date) |
|
316 | |||
317 | /** |
||
318 | * Extract dates from files. |
||
319 | * |
||
320 | * @param array $files |
||
321 | * |
||
322 | * @return array |
||
323 | */ |
||
324 | private function extractDates(array $files) |
||
330 | } |
||
331 |