1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheIconic\Synopsis\Exception; |
4
|
|
|
|
5
|
|
|
use TheIconic\Synopsis\AbstractSynopsis; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* represents an exception trace line |
9
|
|
|
* |
10
|
|
|
* @package TheIconic\Synopsis\Exception |
11
|
|
|
*/ |
12
|
|
|
class TraceSynopsis extends AbstractSynopsis |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string the file |
16
|
|
|
*/ |
17
|
|
|
protected $file; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int the line |
21
|
|
|
*/ |
22
|
|
|
protected $line; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string the class |
26
|
|
|
*/ |
27
|
|
|
protected $class; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string the function |
31
|
|
|
*/ |
32
|
|
|
protected $function; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @see parent::process() |
36
|
|
|
* @param $value |
37
|
|
|
* @param $depth |
38
|
|
|
*/ |
39
|
|
|
public function process($value, $depth) |
40
|
|
|
{ |
41
|
|
|
parent::process($value, $depth); |
42
|
|
|
|
43
|
|
|
$this->type = sprintf('%s()', $this->generateType($value)); |
44
|
|
|
|
45
|
|
|
$this->value = $this->generateValue($value); |
46
|
|
|
|
47
|
|
|
$this->file = $value['file'] ?? ''; |
48
|
|
|
$this->line = $value['line'] ?? ''; |
49
|
|
|
$this->class = $value['class'] ?? ''; |
50
|
|
|
$this->function = $value['function'] ?? ''; |
51
|
|
|
|
52
|
|
|
if (!empty($value['args'])) { |
53
|
|
|
$this->length = count($value['args']); |
54
|
|
|
$this->processArgs($value['args'], $depth); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param array $args |
60
|
|
|
* @param $depth |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
protected function processArgs(array $args, $depth) |
64
|
|
|
{ |
65
|
|
|
if ($depth) { |
66
|
|
|
foreach ($args as $k => $v) { |
67
|
|
|
$this->addChild($this->getFactory()->synopsize($v, $depth), $k); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param array $value |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
protected function generateValue(array $value): string |
79
|
|
|
{ |
80
|
|
|
$file = $value['file'] ?? 'unkown file'; |
81
|
|
|
|
82
|
|
|
if (!array_key_exists('line', $value)) { |
83
|
|
|
return $file; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return sprintf('%s (%d)', $file, $value['line']); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param array $value |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
protected function generateType(array $value): string |
94
|
|
|
{ |
95
|
|
|
if (empty($value['class'])) { |
96
|
|
|
return $value['function']; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $value['class'] . $value['type'] . $value['function']; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
public function getDetails() |
106
|
|
|
{ |
107
|
|
|
return [ |
108
|
|
|
'line' => $this->line, |
109
|
|
|
'file' => $this->file, |
110
|
|
|
'class' => $this->class, |
111
|
|
|
'function' => $this->function, |
112
|
|
|
]; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* get the file |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getFile() |
121
|
|
|
{ |
122
|
|
|
return $this->file; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* get the line |
127
|
|
|
* |
128
|
|
|
* @return int |
129
|
|
|
*/ |
130
|
|
|
public function getLine() |
131
|
|
|
{ |
132
|
|
|
return $this->line; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* get the class |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getClass() |
141
|
|
|
{ |
142
|
|
|
return $this->class; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* get the function |
147
|
|
|
* |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function getFunction() |
151
|
|
|
{ |
152
|
|
|
return $this->function; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|