Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/controller/DiffusionSymbolController.php
12242 views
1
<?php
2
3
final class DiffusionSymbolController extends DiffusionController {
4
5
public function handleRequest(AphrontRequest $request) {
6
$viewer = $this->getViewer();
7
8
// See T13638 for discussion of escaping.
9
$name = $request->getURIData('name');
10
$name = phutil_unescape_uri_path_component($name);
11
12
$query = id(new DiffusionSymbolQuery())
13
->setViewer($viewer)
14
->setName($name);
15
16
if ($request->getStr('context')) {
17
$query->setContext($request->getStr('context'));
18
}
19
20
if ($request->getStr('type')) {
21
$query->setType($request->getStr('type'));
22
}
23
24
if ($request->getStr('lang')) {
25
$query->setLanguage($request->getStr('lang'));
26
}
27
28
$repos = array();
29
if ($request->getStr('repositories')) {
30
$phids = $request->getStr('repositories');
31
$phids = explode(',', $phids);
32
$phids = array_filter($phids);
33
34
if ($phids) {
35
$repos = id(new PhabricatorRepositoryQuery())
36
->setViewer($request->getUser())
37
->withPHIDs($phids)
38
->execute();
39
40
$repo_phids = mpull($repos, 'getPHID');
41
if ($repo_phids) {
42
$query->withRepositoryPHIDs($repo_phids);
43
}
44
}
45
}
46
47
$query->needPaths(true);
48
$query->needRepositories(true);
49
50
$symbols = $query->execute();
51
52
$external_query = id(new DiffusionExternalSymbolQuery())
53
->withNames(array($name));
54
55
if ($request->getStr('context')) {
56
$external_query->withContexts(array($request->getStr('context')));
57
}
58
59
if ($request->getStr('type')) {
60
$external_query->withTypes(array($request->getStr('type')));
61
}
62
63
if ($request->getStr('lang')) {
64
$external_query->withLanguages(array($request->getStr('lang')));
65
}
66
67
if ($request->getStr('path')) {
68
$external_query->withPaths(array($request->getStr('path')));
69
}
70
71
if ($request->getInt('line')) {
72
$external_query->withLines(array($request->getInt('line')));
73
}
74
75
if ($request->getInt('char')) {
76
$external_query->withCharacterPositions(
77
array(
78
$request->getInt('char'),
79
));
80
}
81
82
if ($repos) {
83
$external_query->withRepositories($repos);
84
}
85
86
$external_sources = id(new PhutilClassMapQuery())
87
->setAncestorClass('DiffusionExternalSymbolsSource')
88
->execute();
89
90
$results = array($symbols);
91
foreach ($external_sources as $source) {
92
$source_results = $source->executeQuery($external_query);
93
94
if (!is_array($source_results)) {
95
throw new Exception(
96
pht(
97
'Expected a list of results from external symbol source "%s".',
98
get_class($source)));
99
}
100
101
try {
102
assert_instances_of($source_results, 'PhabricatorRepositorySymbol');
103
} catch (InvalidArgumentException $ex) {
104
throw new Exception(
105
pht(
106
'Expected a list of PhabricatorRepositorySymbol objects '.
107
'from external symbol source "%s".',
108
get_class($source)));
109
}
110
111
$results[] = $source_results;
112
}
113
$symbols = array_mergev($results);
114
115
if ($request->getBool('jump') && count($symbols) == 1) {
116
// If this is a clickthrough from Differential, just jump them
117
// straight to the target if we got a single hit.
118
$symbol = head($symbols);
119
return id(new AphrontRedirectResponse())
120
->setIsExternal($symbol->isExternal())
121
->setURI($symbol->getURI());
122
}
123
124
$rows = array();
125
foreach ($symbols as $symbol) {
126
$href = $symbol->getURI();
127
128
if ($symbol->isExternal()) {
129
$source = $symbol->getSource();
130
$location = $symbol->getLocation();
131
} else {
132
$repo = $symbol->getRepository();
133
$file = $symbol->getPath();
134
$line = $symbol->getLineNumber();
135
136
$source = $repo->getMonogram();
137
$location = $file.':'.$line;
138
}
139
$location = phutil_tag(
140
'a',
141
array(
142
'href' => $href,
143
),
144
$location);
145
146
$rows[] = array(
147
$symbol->getSymbolType(),
148
$symbol->getSymbolContext(),
149
$symbol->getSymbolName(),
150
$symbol->getSymbolLanguage(),
151
$source,
152
$location,
153
);
154
}
155
156
$table = new AphrontTableView($rows);
157
$table->setHeaders(
158
array(
159
pht('Type'),
160
pht('Context'),
161
pht('Name'),
162
pht('Language'),
163
pht('Source'),
164
pht('Location'),
165
));
166
$table->setColumnClasses(
167
array(
168
'',
169
'',
170
'pri',
171
'',
172
'',
173
'',
174
));
175
$table->setNoDataString(
176
pht('No matching symbol could be found in any indexed repository.'));
177
178
$header = id(new PHUIHeaderView())
179
->setHeader(pht('Similar Symbols'))
180
->setHeaderIcon('fa-bullseye');
181
182
$crumbs = $this->buildApplicationCrumbs();
183
$crumbs->addTextCrumb(pht('Find Symbol'));
184
$crumbs->setBorder(true);
185
186
$view = id(new PHUITwoColumnView())
187
->setHeader($header)
188
->setFooter(array(
189
$table,
190
));
191
192
return $this->newPage()
193
->setTitle(pht('Find Symbol'))
194
->setCrumbs($crumbs)
195
->appendChild($view);
196
}
197
198
}
199
200