-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.php
More file actions
110 lines (91 loc) · 3.31 KB
/
Copy pathUtil.php
File metadata and controls
110 lines (91 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Jarboe\Component\Logs;
use App;
use Route;
use Cache;
use File;
use Schema;
use Request;
use Session;
use Input;
use DB;
use Sentinel;
class Util extends \Yaro\Jarboe\Component\AbstractUtil
{
public static function install($command)
{
self::copyIfNotExist($command, 'resources/definitions/logs.php', __DIR__);
if (Schema::hasTable('logs')) {
$command->info(' - Logs table already exists.');
} else {
Schema::create('logs', function($table) {
$table->increments('id')->unsigned();
$table->char('url', 255);
$table->char('exception', 255);
$table->char('message', 255);
$table->char('file', 255);
$table->char('method', 255);
$table->text('trace');
$table->tinyInteger('line');
$table->text('server');
$table->text('headers');
$table->text('request');
$table->text('old_request');
$table->text('file_request');
$table->text('session');
$table->text('cookie');
$table->timestamps();
});
$command->info(' - Logs table created.');
}
} // end install
public static function getNavigationMenuItem()
{
return array(
'title' => 'Логи приложения',
'icon' => 'bug',
'link' => '/logs',
'check' => function() {
return true;
}
);
} // end getNavigationMenuItem
public static function check()
{
$errors = [];
if (!Schema::hasTable('logs')) {
$errors[] = ' - Logs table is missing: run install to create.';
}
return $errors;
} // end check
public static function add($exception)
{
$data = [
'url' => Request::fullUrl(),
'exception' => get_class($exception),
'trace' => $exception->getTraceAsString(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'method' => Request::method(),
'server' => print_r(Request::server(), true),
'headers' => print_r(Request::header(), true),
'request' => print_r(Input::all(), true),
'old_request' => print_r(Request::hasSession() ? Request::old() : [], true),
'file_request' => print_r(Request::file(), true),
'session' => print_r(Request::hasSession() ? Session::all() : [], true),
'cookie' => print_r(Request::cookie(), true),
'created_at' => date('Y-m-d H:i:s'),
];
DB::table('logs')->insert($data);
self::cleanLogsTable();
} // end add
private static function cleanLogsTable()
{
$count = DB::table('logs')->count();
$extra = $count - config('jarboe.c.logs.max_count');
if ($extra > 0) {
DB::table('logs')->orderBy('id', 'asc')->limit($extra)->delete();
}
} // end cleanLogsTable
}