1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TechDeCo\ElasticApmAgent\Message; |
5
|
|
|
|
6
|
|
|
use JsonSerializable; |
7
|
|
|
use TechDeCo\ElasticApmAgent\Serialization; |
8
|
|
|
use function array_merge; |
9
|
|
|
|
10
|
|
|
final class StackTraceFrame implements JsonSerializable |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string|null |
14
|
|
|
*/ |
15
|
|
|
private $absolutePath; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var int|null |
19
|
|
|
*/ |
20
|
|
|
private $columnNumber; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string|null |
24
|
|
|
*/ |
25
|
|
|
private $contextLine; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $fileName; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string|null |
34
|
|
|
*/ |
35
|
|
|
private $function; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var bool|null |
39
|
|
|
*/ |
40
|
|
|
private $isLibraryFrame; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var int |
44
|
|
|
*/ |
45
|
|
|
private $lineNumber; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string|null |
49
|
|
|
*/ |
50
|
|
|
private $module; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string[] |
54
|
|
|
*/ |
55
|
|
|
private $postContext = []; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string[] |
59
|
|
|
*/ |
60
|
|
|
private $preContext = []; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var mixed[] |
64
|
|
|
*/ |
65
|
|
|
private $localVariableList = []; |
66
|
|
|
|
67
|
19 |
|
public function __construct(string $fileName, int $lineNumber) |
68
|
|
|
{ |
69
|
19 |
|
$this->fileName = $fileName; |
70
|
19 |
|
$this->lineNumber = $lineNumber; |
71
|
19 |
|
} |
72
|
|
|
|
73
|
1 |
|
public function atPath(string $absolutePath): self |
74
|
|
|
{ |
75
|
1 |
|
$me = clone $this; |
76
|
1 |
|
$me->absolutePath = $absolutePath; |
77
|
|
|
|
78
|
1 |
|
return $me; |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
public function atColumnNumber(int $columnNumber): self |
82
|
|
|
{ |
83
|
1 |
|
$me = clone $this; |
84
|
1 |
|
$me->columnNumber = $columnNumber; |
85
|
|
|
|
86
|
1 |
|
return $me; |
87
|
|
|
} |
88
|
|
|
|
89
|
1 |
|
public function withLineContext(string $line): self |
90
|
|
|
{ |
91
|
1 |
|
$me = clone $this; |
92
|
1 |
|
$me->contextLine = $line; |
93
|
|
|
|
94
|
1 |
|
return $me; |
95
|
|
|
} |
96
|
|
|
|
97
|
14 |
|
public function inFunction(string $function): self |
98
|
|
|
{ |
99
|
14 |
|
$me = clone $this; |
100
|
14 |
|
$me->function = $function; |
101
|
|
|
|
102
|
14 |
|
return $me; |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
public function originatingFromLibraryCode(): self |
106
|
|
|
{ |
107
|
1 |
|
$me = clone $this; |
108
|
1 |
|
$me->isLibraryFrame = true; |
109
|
|
|
|
110
|
1 |
|
return $me; |
111
|
|
|
} |
112
|
|
|
|
113
|
1 |
|
public function originatingFromUserCode(): self |
114
|
|
|
{ |
115
|
1 |
|
$me = clone $this; |
116
|
1 |
|
$me->isLibraryFrame = false; |
117
|
|
|
|
118
|
1 |
|
return $me; |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
public function inModule(string $module): self |
122
|
|
|
{ |
123
|
1 |
|
$me = clone $this; |
124
|
1 |
|
$me->module = $module; |
125
|
|
|
|
126
|
1 |
|
return $me; |
127
|
|
|
} |
128
|
|
|
|
129
|
1 |
|
public function withPostContext(string ...$line): self |
130
|
|
|
{ |
131
|
1 |
|
$me = clone $this; |
132
|
1 |
|
$me->postContext = array_merge($me->postContext, $line); |
133
|
|
|
|
134
|
1 |
|
return $me; |
135
|
|
|
} |
136
|
|
|
|
137
|
1 |
|
public function withPreContext(string ...$line): self |
138
|
|
|
{ |
139
|
1 |
|
$me = clone $this; |
140
|
1 |
|
$me->preContext = array_merge($me->preContext, $line); |
141
|
|
|
|
142
|
1 |
|
return $me; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param mixed $value |
147
|
|
|
*/ |
148
|
1 |
|
public function withLocalVariable(string $name, $value): self |
149
|
|
|
{ |
150
|
1 |
|
$me = clone $this; |
151
|
1 |
|
$me->localVariableList[$name] = $value; |
152
|
|
|
|
153
|
1 |
|
return $me; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return mixed[] |
158
|
|
|
*/ |
159
|
18 |
|
public function jsonSerialize(): array |
160
|
|
|
{ |
161
|
18 |
|
return Serialization::filterUnset([ |
162
|
18 |
|
'abs_path' => $this->absolutePath, |
163
|
18 |
|
'colno' => $this->columnNumber, |
164
|
18 |
|
'context_line' => $this->contextLine, |
165
|
18 |
|
'filename' => $this->fileName, |
166
|
18 |
|
'function' => $this->function, |
167
|
18 |
|
'library_frame' => $this->isLibraryFrame, |
168
|
18 |
|
'lineno' => $this->lineNumber, |
169
|
18 |
|
'module' => $this->module, |
170
|
18 |
|
'post_context' => $this->postContext, |
171
|
18 |
|
'pre_context' => $this->preContext, |
172
|
18 |
|
'vars' => $this->localVariableList, |
173
|
|
|
]); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|