1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rap2hpoutre\LaravelLogViewer; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Pattern |
7
|
|
|
* @property array patterns |
8
|
|
|
* @package Rap2hpoutre\LaravelLogViewer |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
class Pattern |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var \Illuminate\Foundation\Application | \Laravel\Lumen\Application |
15
|
|
|
*/ |
16
|
|
|
private $app; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
private $patterns = [ |
22
|
|
|
'logs' => '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/', |
23
|
|
|
'current_log' => [ |
24
|
|
|
'/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?)\](?:.*?(\w+)\.|.*?)', |
25
|
|
|
'.+ \{.*"exception":"\[object\] \(([^ ]+)\(code: (\d)\): *(.*?) at (.*?):([0-9]+)\) *\r*\n*$/i', |
26
|
|
|
': (.+) *((\{.+\}))? *\r*\n*$/i', |
27
|
|
|
], |
28
|
|
|
'current_log_string' => '/^([^ ]+): *(.*?) in (.*?):([0-9]+)$/', |
29
|
|
|
'stack_init_section' => '/^\n\[stacktrace\]\n/', |
30
|
|
|
'stack' => [ |
31
|
|
|
'/^(.+)(->|::)([^\(]+)\((.*)\)$/', |
32
|
|
|
'/^([^\(]+)\((.*)\)$/', |
33
|
|
|
'/^(.+)\(([0-9]+)\): (.+)$/', |
34
|
|
|
], |
35
|
|
|
'stack_startWith' => '/^ ?\#? ?[0-9]+ ?/', |
36
|
|
|
'files' => '/\{.*?\,.*?\}/i', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private $patternsLumen = [ |
44
|
|
|
'logs' => '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/', |
45
|
|
|
'current_log' => [ |
46
|
|
|
'/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?)\](?:.*?(\w+)\.|.*?)', |
47
|
|
|
': ([^ ]+):(\d)? *(.*?) in (.*?):([0-9]+)* *\r*\n*/i', |
48
|
|
|
': (.+) *((\{.+\}))? *\r*\n*$/i', |
49
|
|
|
], |
50
|
|
|
'current_log_string' => '/^([^ ]+): *(.*?) in (.*?):([0-9]+)$/', |
51
|
|
|
'stack_init_section' => '/^\nStack trace:\n/', |
52
|
|
|
'stack' => [ |
53
|
|
|
'/^(.+)(->|::)([^\(]+)\((.*)\)$/', |
54
|
|
|
'/^([^\(]+)\((.*)\)$/', |
55
|
|
|
'/^(.+)\(([0-9]+)\): (.+)$/', |
56
|
|
|
], |
57
|
|
|
'stack_startWith' => '/^ ?\#? ?[0-9]+ ?/', |
58
|
|
|
'files' => '/\{.*?\,.*?\}/i', |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Pattern constructor. |
63
|
|
|
*/ |
64
|
|
|
public function __construct() |
65
|
|
|
{ |
66
|
|
|
if (function_exists('app')) { |
67
|
|
|
$this->app = app(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function all() |
75
|
|
|
{ |
76
|
|
|
return array_keys($this->patterns); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param $pattern |
81
|
|
|
* @param null $position |
82
|
|
|
* @return string pattern |
83
|
|
|
*/ |
84
|
|
|
public function getPattern($pattern, $position = null) |
85
|
|
|
{ |
86
|
|
|
$patternVersion = $this->patterns; |
87
|
|
|
if ($this->isLumen()) { |
88
|
|
|
$patternVersion = $this->patternsLumen; |
89
|
|
|
} |
90
|
|
|
if ($position !== null) { |
91
|
|
|
return $patternVersion[$pattern][$position]; |
92
|
|
|
} |
93
|
|
|
return $patternVersion[$pattern]; |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function isLaravel() |
101
|
|
|
{ |
102
|
|
|
if (is_a($this->app, '\Illuminate\Foundation\Application')) { |
103
|
|
|
return true; |
104
|
|
|
} |
105
|
|
|
return false; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
|
|
public function isLumen() |
112
|
|
|
{ |
113
|
|
|
if (is_a($this->app, '\Laravel\Lumen\Application')) { |
114
|
|
|
return true; |
115
|
|
|
} |
116
|
|
|
return false; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|