1
|
|
|
<?php |
2
|
|
|
namespace Rap2hpoutre\LaravelLogViewer; |
3
|
|
|
|
4
|
|
|
if (class_exists("\\Illuminate\\Routing\\Controller")) { |
5
|
|
|
class BaseController extends \Illuminate\Routing\Controller {} |
6
|
|
|
} else if (class_exists("Laravel\\Lumen\\Routing\\Controller")) { |
7
|
|
|
class BaseController extends \Laravel\Lumen\Routing\Controller {} |
|
|
|
|
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
class LogViewerController extends BaseController |
11
|
|
|
{ |
12
|
|
|
protected $request; |
13
|
|
|
|
14
|
|
|
public function __construct () |
15
|
|
|
{ |
16
|
|
|
$this->request = app('request'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function index() |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
if ($this->request->input('l')) { |
23
|
|
|
LaravelLogViewer::setFile(base64_decode($this->request->input('l'))); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if ($this->request->input('dl')) { |
27
|
|
|
return $this->download(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('dl')))); |
28
|
|
|
} elseif ($this->request->has('del')) { |
29
|
|
|
app('files')->delete(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('del')))); |
30
|
|
|
return $this->redirect($this->request->url()); |
31
|
|
|
} elseif ($this->request->has('delall')) { |
32
|
|
|
foreach(LaravelLogViewer::getFiles(true) as $file){ |
33
|
|
|
app('files')->delete(LaravelLogViewer::pathToLogFile($file)); |
34
|
|
|
} |
35
|
|
|
return $this->redirect($this->request->url()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$data = [ |
39
|
|
|
'logs' => LaravelLogViewer::all(), |
40
|
|
|
'files' => LaravelLogViewer::getFiles(true), |
41
|
|
|
'current_file' => LaravelLogViewer::getFileName() |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
if ($this->request->wantsJson()) { |
45
|
|
|
return $data; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return app('view')->make('laravel-log-viewer::log', $data); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function redirect($to) |
52
|
|
|
{ |
53
|
|
|
if (function_exists('redirect')) { |
54
|
|
|
return redirect($to); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return app('redirect')->to($to); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function download($data) |
61
|
|
|
{ |
62
|
|
|
if (function_exists('response')) { |
63
|
|
|
return response()->download($data); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// For laravel 4.2 |
67
|
|
|
return app('\Illuminate\Support\Facades\Response')->download($data); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.