3 final class DiffusionSymbolController
extends DiffusionController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $viewer = $this->getViewer();
8 // See T13638 for discussion of escaping.
9 $name = $request->getURIData('name');
10 $name = phutil_unescape_uri_path_component($name);
12 $query = id(new DiffusionSymbolQuery())
16 if ($request->getStr('context')) {
17 $query->setContext($request->getStr('context'));
20 if ($request->getStr('type')) {
21 $query->setType($request->getStr('type'));
24 if ($request->getStr('lang')) {
25 $query->setLanguage($request->getStr('lang'));
29 if ($request->getStr('repositories')) {
30 $phids = $request->getStr('repositories');
31 $phids = explode(',', $phids);
32 $phids = array_filter($phids);
35 $repos = id(new PhabricatorRepositoryQuery())
36 ->setViewer($request->getUser())
40 $repo_phids = mpull($repos, 'getPHID');
42 $query->withRepositoryPHIDs($repo_phids);
47 $query->needPaths(true);
48 $query->needRepositories(true);
50 $symbols = $query->execute();
52 $external_query = id(new DiffusionExternalSymbolQuery())
53 ->withNames(array($name));
55 if ($request->getStr('context')) {
56 $external_query->withContexts(array($request->getStr('context')));
59 if ($request->getStr('type')) {
60 $external_query->withTypes(array($request->getStr('type')));
63 if ($request->getStr('lang')) {
64 $external_query->withLanguages(array($request->getStr('lang')));
67 if ($request->getStr('path')) {
68 $external_query->withPaths(array($request->getStr('path')));
71 if ($request->getInt('line')) {
72 $external_query->withLines(array($request->getInt('line')));
75 if ($request->getInt('char')) {
76 $external_query->withCharacterPositions(
78 $request->getInt('char'),
83 $external_query->withRepositories($repos);
86 $external_sources = id(new PhutilClassMapQuery())
87 ->setAncestorClass('DiffusionExternalSymbolsSource')
90 $results = array($symbols);
91 foreach ($external_sources as $source) {
92 $source_results = $source->executeQuery($external_query);
94 if (!is_array($source_results)) {
97 'Expected a list of results from external symbol source "%s".',
102 assert_instances_of($source_results, 'PhabricatorRepositorySymbol');
103 } catch (InvalidArgumentException
$ex) {
106 'Expected a list of PhabricatorRepositorySymbol objects '.
107 'from external symbol source "%s".',
108 get_class($source)));
111 $results[] = $source_results;
113 $symbols = array_mergev($results);
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());
125 foreach ($symbols as $symbol) {
126 $href = $symbol->getURI();
128 if ($symbol->isExternal()) {
129 $source = $symbol->getSource();
130 $location = $symbol->getLocation();
132 $repo = $symbol->getRepository();
133 $file = $symbol->getPath();
134 $line = $symbol->getLineNumber();
136 $source = $repo->getMonogram();
137 $location = $file.':'.$line;
139 $location = phutil_tag(
147 $symbol->getSymbolType(),
148 $symbol->getSymbolContext(),
149 $symbol->getSymbolName(),
150 $symbol->getSymbolLanguage(),
156 $table = new AphrontTableView($rows);
166 $table->setColumnClasses(
175 $table->setNoDataString(
176 pht('No matching symbol could be found in any indexed repository.'));
178 $header = id(new PHUIHeaderView())
179 ->setHeader(pht('Similar Symbols'))
180 ->setHeaderIcon('fa-bullseye');
182 $crumbs = $this->buildApplicationCrumbs();
183 $crumbs->addTextCrumb(pht('Find Symbol'));
184 $crumbs->setBorder(true);
186 $view = id(new PHUITwoColumnView())
192 return $this->newPage()
193 ->setTitle(pht('Find Symbol'))
195 ->appendChild($view);