Path: blob/master/src/applications/diffusion/controller/DiffusionSymbolController.php
12242 views
<?php12final class DiffusionSymbolController extends DiffusionController {34public function handleRequest(AphrontRequest $request) {5$viewer = $this->getViewer();67// See T13638 for discussion of escaping.8$name = $request->getURIData('name');9$name = phutil_unescape_uri_path_component($name);1011$query = id(new DiffusionSymbolQuery())12->setViewer($viewer)13->setName($name);1415if ($request->getStr('context')) {16$query->setContext($request->getStr('context'));17}1819if ($request->getStr('type')) {20$query->setType($request->getStr('type'));21}2223if ($request->getStr('lang')) {24$query->setLanguage($request->getStr('lang'));25}2627$repos = array();28if ($request->getStr('repositories')) {29$phids = $request->getStr('repositories');30$phids = explode(',', $phids);31$phids = array_filter($phids);3233if ($phids) {34$repos = id(new PhabricatorRepositoryQuery())35->setViewer($request->getUser())36->withPHIDs($phids)37->execute();3839$repo_phids = mpull($repos, 'getPHID');40if ($repo_phids) {41$query->withRepositoryPHIDs($repo_phids);42}43}44}4546$query->needPaths(true);47$query->needRepositories(true);4849$symbols = $query->execute();5051$external_query = id(new DiffusionExternalSymbolQuery())52->withNames(array($name));5354if ($request->getStr('context')) {55$external_query->withContexts(array($request->getStr('context')));56}5758if ($request->getStr('type')) {59$external_query->withTypes(array($request->getStr('type')));60}6162if ($request->getStr('lang')) {63$external_query->withLanguages(array($request->getStr('lang')));64}6566if ($request->getStr('path')) {67$external_query->withPaths(array($request->getStr('path')));68}6970if ($request->getInt('line')) {71$external_query->withLines(array($request->getInt('line')));72}7374if ($request->getInt('char')) {75$external_query->withCharacterPositions(76array(77$request->getInt('char'),78));79}8081if ($repos) {82$external_query->withRepositories($repos);83}8485$external_sources = id(new PhutilClassMapQuery())86->setAncestorClass('DiffusionExternalSymbolsSource')87->execute();8889$results = array($symbols);90foreach ($external_sources as $source) {91$source_results = $source->executeQuery($external_query);9293if (!is_array($source_results)) {94throw new Exception(95pht(96'Expected a list of results from external symbol source "%s".',97get_class($source)));98}99100try {101assert_instances_of($source_results, 'PhabricatorRepositorySymbol');102} catch (InvalidArgumentException $ex) {103throw new Exception(104pht(105'Expected a list of PhabricatorRepositorySymbol objects '.106'from external symbol source "%s".',107get_class($source)));108}109110$results[] = $source_results;111}112$symbols = array_mergev($results);113114if ($request->getBool('jump') && count($symbols) == 1) {115// If this is a clickthrough from Differential, just jump them116// straight to the target if we got a single hit.117$symbol = head($symbols);118return id(new AphrontRedirectResponse())119->setIsExternal($symbol->isExternal())120->setURI($symbol->getURI());121}122123$rows = array();124foreach ($symbols as $symbol) {125$href = $symbol->getURI();126127if ($symbol->isExternal()) {128$source = $symbol->getSource();129$location = $symbol->getLocation();130} else {131$repo = $symbol->getRepository();132$file = $symbol->getPath();133$line = $symbol->getLineNumber();134135$source = $repo->getMonogram();136$location = $file.':'.$line;137}138$location = phutil_tag(139'a',140array(141'href' => $href,142),143$location);144145$rows[] = array(146$symbol->getSymbolType(),147$symbol->getSymbolContext(),148$symbol->getSymbolName(),149$symbol->getSymbolLanguage(),150$source,151$location,152);153}154155$table = new AphrontTableView($rows);156$table->setHeaders(157array(158pht('Type'),159pht('Context'),160pht('Name'),161pht('Language'),162pht('Source'),163pht('Location'),164));165$table->setColumnClasses(166array(167'',168'',169'pri',170'',171'',172'',173));174$table->setNoDataString(175pht('No matching symbol could be found in any indexed repository.'));176177$header = id(new PHUIHeaderView())178->setHeader(pht('Similar Symbols'))179->setHeaderIcon('fa-bullseye');180181$crumbs = $this->buildApplicationCrumbs();182$crumbs->addTextCrumb(pht('Find Symbol'));183$crumbs->setBorder(true);184185$view = id(new PHUITwoColumnView())186->setHeader($header)187->setFooter(array(188$table,189));190191return $this->newPage()192->setTitle(pht('Find Symbol'))193->setCrumbs($crumbs)194->appendChild($view);195}196197}198199200