1 | <?php |
||
28 | class IncidentsHelper extends AppHelper |
||
29 | { |
||
30 | 2 | public function __construct(View $view, $settings = array()) |
|
34 | |||
35 | public function createIncidentsLinks($incidents) |
||
36 | { |
||
37 | $links = array(); |
||
38 | foreach ($incidents as $incident) { |
||
39 | $links[] = $this->linkToIncident($incident); |
||
40 | } |
||
41 | $string = implode(', ', $links); |
||
42 | |||
43 | return $string; |
||
44 | } |
||
45 | |||
46 | public function linkToIncident($incident) |
||
47 | { |
||
48 | $incidentId = $incident['id']; |
||
49 | $link = "<a href='/" . BASE_DIR . "incidents/view/$incidentId'>#$incidentId</a>"; |
||
50 | |||
51 | return $link; |
||
52 | } |
||
53 | |||
54 | public function incidentsDescriptions($incidents) |
||
55 | { |
||
56 | $descriptions = ''; |
||
57 | foreach ($incidents as $incident) { |
||
58 | $descriptions .= '<span>Incident '; |
||
59 | $descriptions .= $this->linkToIncident($incident); |
||
60 | $descriptions .= ':</span>'; |
||
61 | $descriptions .= '<pre>'; |
||
62 | $descriptions .= htmlspecialchars($incident['steps']); |
||
63 | $descriptions .= '</pre>'; |
||
64 | } |
||
65 | |||
66 | return $descriptions; |
||
67 | } |
||
68 | |||
69 | 1 | public function getStacktrace($incident, $divClass) |
|
70 | { |
||
71 | 1 | $html = ''; |
|
72 | 1 | $html .= "<div class='$divClass'>"; |
|
73 | |||
74 | 1 | if (is_string($incident['stacktrace'])) { |
|
75 | $incident['stacktrace'] = |
||
76 | json_decode($incident['stacktrace'], true); |
||
77 | } |
||
78 | |||
79 | 1 | foreach ($incident['stacktrace'] as $level) { |
|
80 | 1 | $exception_type = (($incident['exception_type']) ? ('php') : ('js')); |
|
81 | 1 | $html .= $this->_getStackLevelInfo($level, $exception_type); |
|
82 | $html .= "<pre class='brush: " |
||
83 | 1 | . $exception_type |
|
84 | 1 | . '; tab-size: 2'; |
|
85 | 1 | 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 | 1 | $html .= "'>"; |
|
94 | |||
95 | 1 | if ($exception_type == 'js') { |
|
96 | 1 | $html .= htmlspecialchars(join("\n", $level['context'])); |
|
97 | } else { |
||
98 | $html .= htmlspecialchars($level['function']); |
||
99 | $html .= '('; |
||
100 | $argList = ''; |
||
101 | if (count($level['args']) > 0) { |
||
102 | foreach ($level['args'] as $arg) { |
||
103 | $argList .= "\n" |
||
104 | . gettype($arg) |
||
105 | . ' => ' |
||
106 | . $arg; |
||
107 | $argList .= ','; |
||
108 | } |
||
109 | $argList = substr($argList, 0, (strlen($argList) - 1)); |
||
110 | $argList .= "\n"; |
||
111 | } |
||
112 | $html .= htmlspecialchars($argList); |
||
113 | $html .= ')'; |
||
114 | } |
||
115 | 1 | $html .= '</pre>'; |
|
116 | } |
||
117 | 1 | $html .= '</div>'; |
|
118 | |||
119 | 1 | return $html; |
|
120 | } |
||
121 | |||
122 | 1 | protected function _getStackLevelInfo($level, $exception_type = 'js') |
|
139 | } |
||
140 |