1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Honeybadger; |
4
|
|
|
|
5
|
|
|
use Honeybadger\Support\Arr; |
6
|
|
|
use Honeybadger\Support\Repository; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request as FoundationRequest; |
8
|
|
|
use Throwable; |
9
|
|
|
|
10
|
|
|
class ExceptionNotification |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \Honeybadger\Config |
14
|
|
|
*/ |
15
|
|
|
protected $config; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \Honeybadger\Support\Repository |
19
|
|
|
*/ |
20
|
|
|
protected $context; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Throwable |
24
|
|
|
*/ |
25
|
|
|
protected $throwable; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Honeybadger\BacktraceFactory |
29
|
|
|
*/ |
30
|
|
|
protected $backtrace; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \Honeybadger\Request |
34
|
|
|
*/ |
35
|
|
|
protected $request; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \Honeybadger\Environment |
39
|
|
|
*/ |
40
|
|
|
protected $environment; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $additionalParams; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \Honeybadger\Config $config |
49
|
|
|
* @param \Honeybadger\Support\Repository $context |
50
|
|
|
*/ |
51
|
|
|
public function __construct(Config $config, Repository $context) |
52
|
|
|
{ |
53
|
|
|
$this->config = $config; |
54
|
|
|
$this->context = $context; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param \Throwable $e |
59
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
60
|
|
|
* @param array $additionalParams |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function make(Throwable $e, FoundationRequest $request = null, array $additionalParams = []): array |
64
|
|
|
{ |
65
|
|
|
$this->throwable = $e; |
66
|
|
|
$this->backtrace = $this->makeBacktrace(); |
67
|
|
|
$this->request = $this->makeRequest($request); |
68
|
|
|
$this->additionalParams = $additionalParams; |
69
|
|
|
$this->environment = $this->makeEnvironment(); |
70
|
|
|
|
71
|
|
|
return $this->format(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
private function format(): array |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
'notifier' => $this->config['notifier'], |
81
|
|
|
'error' => [ |
82
|
|
|
'class' => get_class($this->throwable), |
83
|
|
|
'message' => $this->throwable->getMessage(), |
84
|
|
|
'backtrace' => $this->backtrace->trace(), |
85
|
|
|
'causes' => $this->backtrace->previous(), |
86
|
|
|
'fingerprint' => Arr::get($this->additionalParams, 'fingerprint', null), |
87
|
|
|
'tags' => Arr::wrap(Arr::get($this->additionalParams, 'tags', null)), |
88
|
|
|
], |
89
|
|
|
'request' => [ |
90
|
|
|
'cgi_data' => $this->environment->values(), |
91
|
|
|
'params' => $this->request->params(), |
92
|
|
|
'session' => $this->request->session(), |
93
|
|
|
'url' => $this->request->url(), |
94
|
|
|
'context' => $this->context->except(['honeybadger_component', 'honeybadger_action']), |
95
|
|
|
'component' => Arr::get($this->additionalParams, 'component', null) ?? Arr::get($this->context, 'honeybadger_component', null), |
96
|
|
|
'action' => Arr::get($this->additionalParams, 'action', null) ?? Arr::get($this->context, 'honeybadger_action', null), |
97
|
|
|
], |
98
|
|
|
'server' => [ |
99
|
|
|
'pid' => getmypid(), |
100
|
|
|
'version' => $this->config['version'], |
101
|
|
|
'hostname' => $this->config['hostname'], |
102
|
|
|
'project_root' => $this->config['project_root'], |
103
|
|
|
'environment_name' => $this->config['environment_name'], |
104
|
|
|
], |
105
|
|
|
]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return \Honeybadger\Environment |
110
|
|
|
*/ |
111
|
|
|
private function makeEnvironment(): Environment |
112
|
|
|
{ |
113
|
|
|
return (new Environment) |
114
|
|
|
->filterKeys($this->config['environment']['filter']) |
115
|
|
|
->include($this->config['environment']['include']); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return \Honeybadger\BacktraceFactory |
120
|
|
|
*/ |
121
|
|
|
private function makeBacktrace(): BacktraceFactory |
122
|
|
|
{ |
123
|
|
|
return new BacktraceFactory($this->throwable); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
128
|
|
|
* @return \Honeybadger\Request |
129
|
|
|
*/ |
130
|
|
|
private function makeRequest(FoundationRequest $request = null): Request |
131
|
|
|
{ |
132
|
|
|
return (new Request($request)) |
133
|
|
|
->filterKeys($this->config['request']['filter']); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|