1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
4
|
|
|
/** |
5
|
|
|
* Incidents View helper. |
6
|
|
|
* |
7
|
|
|
* phpMyAdmin Error reporting server |
8
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
9
|
|
|
* |
10
|
|
|
* Licensed under The MIT License |
11
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
13
|
|
|
* |
14
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
15
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
16
|
|
|
* |
17
|
|
|
* @see https://www.phpmyadmin.net/ |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace App\View\Helper; |
21
|
|
|
|
22
|
|
|
use App\View\Helper\AppHelper; |
23
|
|
|
use Cake\View\View; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Incidents View helper. |
27
|
|
|
*/ |
28
|
|
|
class IncidentsHelper extends AppHelper |
29
|
|
|
{ |
30
|
3 |
|
public function __construct(View $view, $settings = []) |
31
|
|
|
{ |
32
|
3 |
|
parent::__construct($view, $settings); |
33
|
3 |
|
} |
34
|
|
|
|
35
|
1 |
|
public function createIncidentsLinks($incidents) |
36
|
|
|
{ |
37
|
1 |
|
$links = []; |
38
|
1 |
|
foreach ($incidents as $incident) { |
39
|
1 |
|
$links[] = $this->linkToIncident($incident); |
40
|
|
|
} |
41
|
1 |
|
$string = implode(', ', $links); |
42
|
|
|
|
43
|
1 |
|
return $string; |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function linkToIncident($incident) |
47
|
|
|
{ |
48
|
1 |
|
$incidentId = $incident['id']; |
49
|
1 |
|
$link = "<a href='/" . BASE_DIR . "incidents/view/$incidentId'>#$incidentId</a>"; |
50
|
|
|
|
51
|
1 |
|
return $link; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
public function incidentsDescriptions($incidents) |
55
|
|
|
{ |
56
|
1 |
|
$descriptions = ''; |
57
|
1 |
|
foreach ($incidents as $incident) { |
58
|
1 |
|
$descriptions .= '<span>Incident '; |
59
|
1 |
|
$descriptions .= $this->linkToIncident($incident); |
60
|
1 |
|
$descriptions .= ':</span>'; |
61
|
1 |
|
$descriptions .= '<pre>'; |
62
|
1 |
|
$descriptions .= htmlspecialchars($incident['steps']); |
63
|
1 |
|
$descriptions .= '</pre>'; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
return $descriptions; |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
public function getStacktrace($incident, $divClass) |
70
|
|
|
{ |
71
|
2 |
|
$html = ''; |
72
|
2 |
|
$html .= "<div class='$divClass'>"; |
73
|
|
|
|
74
|
2 |
|
if (is_string($incident['stacktrace'])) { |
75
|
1 |
|
$incident['stacktrace'] = |
76
|
1 |
|
json_decode($incident['stacktrace'], true); |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
foreach ($incident['stacktrace'] as $level) { |
80
|
2 |
|
$exception_type = (($incident['exception_type']) ? ('php') : ('js')); |
81
|
2 |
|
$html .= $this->_getStackLevelInfo($level, $exception_type); |
82
|
|
|
$html .= "<pre class='brush: " |
83
|
2 |
|
. $exception_type |
84
|
2 |
|
. '; tab-size: 2'; |
85
|
2 |
|
if (isset($level['line']) && $level['line']) { |
86
|
|
|
if ($incident['exception_type']) { |
87
|
|
|
$html .= '; first-line: ' . (int) $level['line']; |
88
|
|
|
} elseif ((int) $level['line'] > 5) { |
89
|
|
|
$html .= '; first-line: ' . ((int) $level['line'] - 5); |
90
|
|
|
} |
91
|
|
|
$html .= '; highlight: [' . (int) $level['line'] . ']'; |
92
|
|
|
} |
93
|
2 |
|
$html .= "'>"; |
94
|
|
|
|
95
|
2 |
|
if ($exception_type == 'js') { |
96
|
2 |
|
if (isset($level['context'])) { |
97
|
2 |
|
$html .= htmlspecialchars(join("\n", $level['context'])); |
98
|
|
|
} |
99
|
|
|
} else { |
100
|
|
|
$html .= htmlspecialchars($level['function']); |
101
|
|
|
$html .= '('; |
102
|
|
|
$argList = ''; |
103
|
|
|
if (count($level['args']) > 0) { |
104
|
|
|
foreach ($level['args'] as $arg) { |
105
|
|
|
$argList .= "\n" |
106
|
|
|
. gettype($arg) |
107
|
|
|
. ' => ' |
108
|
|
|
. $arg; |
109
|
|
|
$argList .= ','; |
110
|
|
|
} |
111
|
|
|
$argList = substr($argList, 0, (strlen($argList) - 1)); |
112
|
|
|
$argList .= "\n"; |
113
|
|
|
} |
114
|
|
|
$html .= htmlspecialchars($argList); |
115
|
|
|
$html .= ')'; |
116
|
|
|
} |
117
|
2 |
|
$html .= '</pre>'; |
118
|
|
|
} |
119
|
2 |
|
$html .= '</div>'; |
120
|
|
|
|
121
|
2 |
|
return $html; |
122
|
|
|
} |
123
|
|
|
|
124
|
2 |
|
protected function _getStackLevelInfo($level, $exception_type = 'js') |
125
|
|
|
{ |
126
|
2 |
|
$html = '<span>'; |
127
|
2 |
|
if ($exception_type == 'js') { |
128
|
|
|
$elements = [ |
129
|
2 |
|
'filename', |
130
|
|
|
'scriptname', |
131
|
|
|
'line', |
132
|
|
|
'func', |
133
|
|
|
'column', |
134
|
|
|
]; |
135
|
|
|
} else { |
136
|
|
|
$elements = [ |
137
|
|
|
'file', |
138
|
|
|
'line', |
139
|
|
|
'function', |
140
|
|
|
'class', |
141
|
|
|
]; |
142
|
|
|
} |
143
|
2 |
|
foreach ($elements as $element) { |
144
|
2 |
|
if (isset($level[$element])) { |
145
|
|
|
$html .= "$element: " . $level[$element] . '; '; |
146
|
|
|
} |
147
|
|
|
} |
148
|
2 |
|
$html .= '</span>'; |
149
|
|
|
|
150
|
2 |
|
return $html; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|