1 | <?php namespace Arcanedev\LogViewer\Utilities; |
||
15 | class LogChecker implements LogCheckerInterface |
||
16 | { |
||
17 | /* ------------------------------------------------------------------------------------------------ |
||
18 | | Constants |
||
19 | | ------------------------------------------------------------------------------------------------ |
||
20 | */ |
||
21 | /** |
||
22 | * @link http://laravel.com/docs/5.1/errors#configuration |
||
23 | * @link https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md#log-to-files-and-syslog |
||
24 | */ |
||
25 | const HANDLER_DAILY = 'daily'; |
||
26 | const HANDLER_SINGLE = 'single'; |
||
27 | const HANDLER_SYSLOG = 'syslog'; |
||
28 | const HANDLER_ERRORLOG = 'errorlog'; |
||
29 | |||
30 | /* ------------------------------------------------------------------------------------------------ |
||
31 | | Properties |
||
32 | | ------------------------------------------------------------------------------------------------ |
||
33 | */ |
||
34 | /** |
||
35 | * The config repository instance. |
||
36 | * |
||
37 | * @var \Illuminate\Contracts\Config\Repository |
||
38 | */ |
||
39 | private $config; |
||
40 | |||
41 | /** |
||
42 | * The filesystem instance. |
||
43 | * |
||
44 | * @var \Arcanedev\LogViewer\Contracts\FilesystemInterface |
||
45 | */ |
||
46 | private $filesystem; |
||
47 | |||
48 | /** |
||
49 | * Log handler mode. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $handler = ''; |
||
54 | |||
55 | /** |
||
56 | * The check status. |
||
57 | * |
||
58 | * @var bool |
||
59 | */ |
||
60 | private $status = true; |
||
61 | |||
62 | /** |
||
63 | * The check messages. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | private $messages; |
||
68 | |||
69 | /** |
||
70 | * Log files status (or statuses... i don't know). |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | private $files; |
||
75 | |||
76 | /* ------------------------------------------------------------------------------------------------ |
||
77 | | Constructor |
||
78 | | ------------------------------------------------------------------------------------------------ |
||
79 | */ |
||
80 | /** |
||
81 | * Make LogChecker instance. |
||
82 | * |
||
83 | * @param \Illuminate\Contracts\Config\Repository $config |
||
84 | * @param \Arcanedev\LogViewer\Contracts\FilesystemInterface $filesystem |
||
85 | */ |
||
86 | 18 | public function __construct(Config $config, FilesystemInterface $filesystem) |
|
94 | |||
95 | /* ------------------------------------------------------------------------------------------------ |
||
96 | | Getters & Setters |
||
97 | | ------------------------------------------------------------------------------------------------ |
||
98 | */ |
||
99 | /** |
||
100 | * Set the config instance. |
||
101 | * |
||
102 | * @param \Illuminate\Contracts\Config\Repository $config |
||
103 | * |
||
104 | * @return self |
||
105 | */ |
||
106 | 18 | public function setConfig(Config $config) |
|
112 | |||
113 | /** |
||
114 | * Set the Filesystem instance. |
||
115 | * |
||
116 | * @param \Arcanedev\LogViewer\Contracts\FilesystemInterface $filesystem |
||
117 | * |
||
118 | * @return self |
||
119 | */ |
||
120 | 18 | public function setFilesystem(FilesystemInterface $filesystem) |
|
126 | |||
127 | /** |
||
128 | * Set the log handler mode. |
||
129 | * |
||
130 | * @param string $handler |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | 18 | protected function setHandler($handler) |
|
140 | |||
141 | /* ------------------------------------------------------------------------------------------------ |
||
142 | | Main Functions |
||
143 | | ------------------------------------------------------------------------------------------------ |
||
144 | */ |
||
145 | /** |
||
146 | * Get messages. |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | 6 | public function messages() |
|
156 | |||
157 | /** |
||
158 | * Check if the check passes. |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | 3 | public function passes() |
|
168 | |||
169 | /** |
||
170 | * Check if the check fails. |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | 3 | public function fails() |
|
178 | |||
179 | /** |
||
180 | * Get the requirements. |
||
181 | * |
||
182 | * @return array |
||
183 | */ |
||
184 | 9 | public function requirements() |
|
202 | |||
203 | /* ------------------------------------------------------------------------------------------------ |
||
204 | | Check Functions |
||
205 | | ------------------------------------------------------------------------------------------------ |
||
206 | */ |
||
207 | /** |
||
208 | * Is a daily handler mode ? |
||
209 | * |
||
210 | * @return bool |
||
211 | */ |
||
212 | 18 | protected function isDaily() |
|
216 | |||
217 | /** |
||
218 | * Is the handler is the same as the application log handler. |
||
219 | * |
||
220 | * @param string $handler |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | 18 | private function isSameHandler($handler) |
|
228 | |||
229 | /* ------------------------------------------------------------------------------------------------ |
||
230 | | Other Functions |
||
231 | | ------------------------------------------------------------------------------------------------ |
||
232 | */ |
||
233 | /** |
||
234 | * Refresh the checks. |
||
235 | * |
||
236 | * @return self |
||
237 | */ |
||
238 | 18 | private function refresh() |
|
253 | |||
254 | /** |
||
255 | * Check the handler mode |
||
256 | */ |
||
257 | 18 | private function checkHandler() |
|
268 | |||
269 | /** |
||
270 | * Check all log files. |
||
271 | * |
||
272 | * @return array |
||
273 | */ |
||
274 | 18 | private function checkLogFiles() |
|
280 | |||
281 | /** |
||
282 | * Check a log file. |
||
283 | * |
||
284 | * @param string $path |
||
285 | */ |
||
286 | 18 | private function checkLogFile($path) |
|
306 | |||
307 | /** |
||
308 | * Check if it's not a single log file. |
||
309 | * |
||
310 | * @param string $file |
||
311 | * |
||
312 | * @return bool |
||
313 | */ |
||
314 | 18 | private function isSingleLogFile($file) |
|
318 | |||
319 | /** |
||
320 | * Check the date of the log file. |
||
321 | * |
||
322 | * @param string $file |
||
323 | * |
||
324 | * @return bool |
||
325 | */ |
||
326 | 18 | private function isInvalidLogDate($file) |
|
336 | } |
||
337 |