|
1
|
|
|
<?php |
|
2
|
|
|
namespace Rap2hpoutre\LaravelLogViewer; |
|
3
|
|
|
use Illuminate\Support\Facades\Crypt; |
|
4
|
|
|
|
|
5
|
|
|
if (class_exists("\\Illuminate\\Routing\\Controller")) { |
|
6
|
|
|
class BaseController extends \Illuminate\Routing\Controller {} |
|
7
|
|
|
} else if (class_exists("Laravel\\Lumen\\Routing\\Controller")) { |
|
8
|
|
|
class BaseController extends \Laravel\Lumen\Routing\Controller {} |
|
|
|
|
|
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
class LogViewerController extends BaseController |
|
12
|
|
|
{ |
|
13
|
|
|
protected $request; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct () |
|
16
|
|
|
{ |
|
17
|
|
|
$this->request = app('request'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function index() |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
if ($this->request->input('l')) { |
|
24
|
|
|
LaravelLogViewer::setFile(Crypt::decrypt($this->request->input('l'))); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
if ($this->request->input('dl')) { |
|
28
|
|
|
return $this->download(LaravelLogViewer::pathToLogFile(Crypt::decrypt($this->request->input('dl')))); |
|
29
|
|
|
} elseif ($this->request->has('del')) { |
|
30
|
|
|
app('files')->delete(LaravelLogViewer::pathToLogFile(Crypt::decrypt($this->request->input('del')))); |
|
31
|
|
|
return $this->redirect($this->request->url()); |
|
32
|
|
|
} elseif ($this->request->has('delall')) { |
|
33
|
|
|
foreach(LaravelLogViewer::getFiles(true) as $file){ |
|
34
|
|
|
app('files')->delete(LaravelLogViewer::pathToLogFile($file)); |
|
35
|
|
|
} |
|
36
|
|
|
return $this->redirect($this->request->url()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$data = [ |
|
40
|
|
|
'logs' => LaravelLogViewer::all(), |
|
41
|
|
|
'files' => LaravelLogViewer::getFiles(true), |
|
42
|
|
|
'current_file' => LaravelLogViewer::getFileName(), |
|
43
|
|
|
'standardFormat' => true, |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
if ($this->request->wantsJson()) { |
|
47
|
|
|
return $data; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$firstLog = reset($data['logs']); |
|
51
|
|
|
if (!$firstLog['context'] && !$firstLog['level']) { |
|
52
|
|
|
$data['standardFormat'] = false; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return app('view')->make('laravel-log-viewer::log', $data); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function redirect($to) |
|
59
|
|
|
{ |
|
60
|
|
|
if (function_exists('redirect')) { |
|
61
|
|
|
return redirect($to); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return app('redirect')->to($to); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function download($data) |
|
68
|
|
|
{ |
|
69
|
|
|
if (function_exists('response')) { |
|
70
|
|
|
return response()->download($data); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
// For laravel 4.2 |
|
74
|
|
|
return app('\Illuminate\Support\Facades\Response')->download($data); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks for classes that have been defined more than once in the same file.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.