1
|
|
|
<?php |
2
|
|
|
/* vim: set noexpandtab sw=2 ts=2 sts=2: */ |
3
|
|
|
namespace app\View\Helper; |
4
|
|
|
|
5
|
|
|
use App\Utility\Sanitize; |
6
|
|
|
use App\View\Helper\AppHelper; |
7
|
|
|
use Cake\View\View; |
8
|
|
|
|
9
|
|
|
class IncidentsHelper extends AppHelper { |
10
|
|
|
|
11
|
3 |
|
public function __construct(View $view, $settings = array()) { |
12
|
3 |
|
parent::__construct($view, $settings); |
13
|
3 |
|
} |
14
|
|
|
|
15
|
1 |
|
public function createIncidentsLinks($incidents) { |
16
|
1 |
|
$links = array(); |
17
|
1 |
|
foreach ($incidents as $incident) { |
18
|
1 |
|
$links[] = $this->linkToIncident($incident); |
19
|
|
|
} |
20
|
1 |
|
$string = implode(", ", $links); |
21
|
1 |
|
return $string; |
22
|
|
|
} |
23
|
|
|
|
24
|
1 |
|
public function linkToIncident($incident) { |
25
|
1 |
|
$incidentId = $incident["id"]; |
26
|
1 |
|
$link = "<a href='/" . BASE_DIR . "incidents/view/$incidentId'>#$incidentId</a>"; |
27
|
1 |
|
return $link; |
28
|
|
|
} |
29
|
|
|
|
30
|
1 |
|
public function incidentsDescriptions($incidents) { |
31
|
1 |
|
$descriptions = ""; |
32
|
1 |
|
foreach ($incidents as $incident) { |
33
|
1 |
|
$descriptions .= "<span>Incident "; |
34
|
1 |
|
$descriptions .= $this->linkToIncident($incident); |
35
|
1 |
|
$descriptions .= ":</span>"; |
36
|
1 |
|
$descriptions .= "<pre>"; |
37
|
1 |
|
$descriptions .= $incident["steps"]; |
38
|
1 |
|
$descriptions .= "</pre>"; |
39
|
|
|
} |
40
|
1 |
|
return $descriptions; |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
public function getStacktrace($incident, $divClass) { |
44
|
2 |
|
$html = ""; |
45
|
2 |
|
$html .= "<div class='$divClass'>"; |
46
|
|
|
|
47
|
2 |
|
if (is_string($incident["stacktrace"])) { |
48
|
1 |
|
$incident["stacktrace"] = |
49
|
1 |
|
json_decode($incident["stacktrace"], true); |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
foreach ($incident["stacktrace"] as $level) { |
53
|
2 |
|
$exception_type = (($incident["exception_type"])?('php'):('js')); |
54
|
2 |
|
$html .= $this->_getStackLevelInfo($level, $exception_type); |
55
|
|
|
$html .= "<pre class='brush: " |
56
|
2 |
|
. $exception_type |
57
|
2 |
|
. "; tab-size: 2"; |
58
|
2 |
|
if (isset($level['line']) && $level['line']) { |
59
|
|
|
if ($incident['exception_type']) { |
60
|
|
|
$html .= "; first-line: " . (int)$level['line']; |
61
|
|
|
} elseif ((int)$level['line'] > 5) { |
62
|
|
|
$html .= "; first-line: " . ((int)$level['line'] - 5); |
63
|
|
|
} |
64
|
|
|
$html .= "; highlight: [" . (int)$level['line'] . "]"; |
65
|
|
|
} |
66
|
2 |
|
$html .= "'>"; |
67
|
|
|
|
68
|
2 |
|
if($exception_type == 'js') { |
69
|
2 |
|
$html .= htmlspecialchars(join("\n", $level["context"])); |
70
|
|
|
} else { |
71
|
|
|
$html .= htmlspecialchars($level["function"]); |
72
|
|
|
$html .= "("; |
73
|
|
|
$argList = ""; |
74
|
|
|
if (count($level["args"]) > 0) { |
75
|
|
|
foreach ($level["args"] as $arg) { |
76
|
|
|
$argList .= "\n" |
77
|
|
|
. getType($arg) |
78
|
|
|
. " => " |
79
|
|
|
. $arg; |
80
|
|
|
$argList .= ","; |
81
|
|
|
} |
82
|
|
|
$argList = substr($argList, 0, (strlen($argList)-1)); |
83
|
|
|
$argList .= "\n"; |
84
|
|
|
} |
85
|
|
|
$html .= htmlspecialchars($argList); |
86
|
|
|
$html .= ")"; |
87
|
|
|
} |
88
|
2 |
|
$html .= "</pre>"; |
89
|
|
|
} |
90
|
2 |
|
$html .= "</div>"; |
91
|
2 |
|
return $html; |
92
|
|
|
} |
93
|
|
|
|
94
|
2 |
|
protected function _getStackLevelInfo($level, $exception_type = 'js') { |
95
|
2 |
|
$html = "<span>"; |
96
|
2 |
|
if ($exception_type == 'js') { |
97
|
2 |
|
$elements = array("filename", "scriptname", "line", "func", "column"); |
98
|
|
|
} else { |
99
|
|
|
$elements = array("file", "line", "function", "class"); |
100
|
|
|
} |
101
|
2 |
|
foreach ($elements as $element) { |
102
|
2 |
|
if (isset($level[$element])) { |
103
|
2 |
|
$html .= "$element: " . $level[$element] . "; "; |
104
|
|
|
} |
105
|
|
|
} |
106
|
2 |
|
$html .= "</span>"; |
107
|
2 |
|
return $html; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|