Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/widget/AphrontStackTraceView.php
12249 views
1
<?php
2
3
final class AphrontStackTraceView extends AphrontView {
4
5
private $trace;
6
7
public function setTrace($trace) {
8
$this->trace = $trace;
9
return $this;
10
}
11
12
public function render() {
13
$trace = $this->trace;
14
15
$libraries = PhutilBootloader::getInstance()->getAllLibraries();
16
17
// TODO: Make this configurable?
18
$path = 'https://secure.phabricator.com/diffusion/%s/browse/master/src/';
19
20
$callsigns = array(
21
'arcanist' => 'ARC',
22
'phabricator' => 'P',
23
);
24
25
$rows = array();
26
$depth = count($trace);
27
foreach ($trace as $part) {
28
$lib = null;
29
$file = idx($part, 'file');
30
$relative = $file;
31
foreach ($libraries as $library) {
32
$root = phutil_get_library_root($library);
33
if ($file !== null && Filesystem::isDescendant($file, $root)) {
34
$lib = $library;
35
$relative = Filesystem::readablePath($file, $root);
36
break;
37
}
38
}
39
40
$where = '';
41
if (isset($part['class'])) {
42
$where .= $part['class'].'::';
43
}
44
if (isset($part['function'])) {
45
$where .= $part['function'].'()';
46
}
47
48
if ($file) {
49
if (isset($callsigns[$lib])) {
50
$attrs = array('title' => $file);
51
if (empty($attrs['href'])) {
52
$attrs['href'] = sprintf($path, $callsigns[$lib]).
53
str_replace(DIRECTORY_SEPARATOR, '/', $relative).
54
'$'.$part['line'];
55
$attrs['target'] = '_blank';
56
}
57
$file_name = phutil_tag(
58
'a',
59
$attrs,
60
$relative);
61
} else {
62
$file_name = phutil_tag(
63
'span',
64
array(
65
'title' => $file,
66
),
67
$relative);
68
}
69
$file_name = hsprintf('%s : %d', $file_name, $part['line']);
70
} else {
71
$file_name = phutil_tag('em', array(), '(Internal)');
72
}
73
74
75
$rows[] = array(
76
$depth--,
77
$lib,
78
$file_name,
79
$where,
80
);
81
}
82
$table = new AphrontTableView($rows);
83
$table->setHeaders(
84
array(
85
pht('Depth'),
86
pht('Library'),
87
pht('File'),
88
pht('Where'),
89
));
90
$table->setColumnClasses(
91
array(
92
'n',
93
'',
94
'',
95
'wide',
96
));
97
98
return phutil_tag(
99
'div',
100
array(
101
'class' => 'exception-trace',
102
),
103
$table->render());
104
}
105
106
}
107
108