Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionSymbolController.php
<?php | <?php | ||||
final class DiffusionSymbolController extends DiffusionController { | final class DiffusionSymbolController extends DiffusionController { | ||||
private $name; | private $name; | ||||
protected function processDiffusionRequest(AphrontRequest $request) { | protected function processDiffusionRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$this->name = $request->getURIData('name'); | $this->name = $request->getURIData('name'); | ||||
$query = id(new DiffusionSymbolQuery()) | $query = id(new DiffusionSymbolQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->setName($this->name); | ->setName($this->name); | ||||
if ($request->getStr('context') !== null) { | if ($request->getStr('context')) { | ||||
$query->setContext($request->getStr('context')); | $query->setContext($request->getStr('context')); | ||||
} | } | ||||
if ($request->getStr('type')) { | if ($request->getStr('type')) { | ||||
$query->setType($request->getStr('type')); | $query->setType($request->getStr('type')); | ||||
} | } | ||||
if ($request->getStr('lang')) { | if ($request->getStr('lang')) { | ||||
Show All 18 Lines | if ($request->getStr('repositories')) { | ||||
} | } | ||||
} | } | ||||
$query->needPaths(true); | $query->needPaths(true); | ||||
$query->needRepositories(true); | $query->needRepositories(true); | ||||
$symbols = $query->execute(); | $symbols = $query->execute(); | ||||
// For PHP builtins, jump to php.net documentation. | |||||
if ($request->getBool('jump') && count($symbols) == 0) { | |||||
if ($request->getStr('lang', 'php') == 'php') { | $external_query = id(new DiffusionExternalSymbolQuery()) | ||||
if ($request->getStr('type', 'function') == 'function') { | ->withNames(array($this->name)); | ||||
$functions = get_defined_functions(); | |||||
if (in_array($this->name, $functions['internal'])) { | if ($request->getStr('context')) { | ||||
return id(new AphrontRedirectResponse()) | $external_query->withContexts(array($request->getStr('context'))); | ||||
->setIsExternal(true) | |||||
->setURI('http://www.php.net/function.'.$this->name); | |||||
} | |||||
} | |||||
if ($request->getStr('type', 'class') == 'class') { | |||||
if (class_exists($this->name, false) || | |||||
interface_exists($this->name, false)) { | |||||
if (id(new ReflectionClass($this->name))->isInternal()) { | |||||
return id(new AphrontRedirectResponse()) | |||||
->setIsExternal(true) | |||||
->setURI('http://www.php.net/class.'.$this->name); | |||||
} | } | ||||
if ($request->getStr('type')) { | |||||
$external_query->withTypes(array($request->getStr('type'))); | |||||
} | } | ||||
if ($request->getStr('lang')) { | |||||
$external_query->withLanguages(array($request->getStr('lang'))); | |||||
} | } | ||||
$external_sources = id(new PhutilSymbolLoader()) | |||||
->setAncestorClass('DiffusionExternalSymbolsSource') | |||||
->loadObjects(); | |||||
$results = array($symbols); | |||||
avivey: I wanted to explicitly have the indexed results first, but maybe the built-ins should go first… | |||||
Not Done Inline ActionsPutting indexed results first feels like it's probably the better behavior to me, too. If you have 100+ results the query and/or the way you're building or configuring your symbols probably aren't great anyway. epriestley: Putting indexed results first feels like it's probably the better behavior to me, too.
If you… | |||||
foreach ($external_sources as $source) { | |||||
$results[] = $source->executeQuery($external_query); | |||||
} | } | ||||
$symbols = array_mergev($results); | |||||
if ($request->getBool('jump') && count($symbols) == 1) { | |||||
// If this is a clickthrough from Differential, just jump them | |||||
// straight to the target if we got a single hit. | |||||
$symbol = head($symbols); | |||||
return id(new AphrontRedirectResponse()) | |||||
->setIsExternal($symbol->isExternal()) | |||||
->setURI($symbol->getURI()); | |||||
} | } | ||||
$rows = array(); | $rows = array(); | ||||
foreach ($symbols as $symbol) { | foreach ($symbols as $symbol) { | ||||
$file = $symbol->getPath(); | $href = $symbol->getURI(); | ||||
$line = $symbol->getLineNumber(); | |||||
if ($symbol->isExternal()) { | |||||
$source = $symbol->getSource(); | |||||
$location = $symbol->getLocation(); | |||||
} else { | |||||
$repo = $symbol->getRepository(); | $repo = $symbol->getRepository(); | ||||
if ($repo) { | $file = $symbol->getPath(); | ||||
$href = $symbol->getURI(); | $line = $symbol->getLineNumber(); | ||||
if ($request->getBool('jump') && count($symbols) == 1) { | $source = $repo->getMonogram(); | ||||
// If this is a clickthrough from Differential, just jump them | $location = $file.':'.$line; | ||||
// straight to the target if we got a single hit. | |||||
return id(new AphrontRedirectResponse())->setURI($href); | |||||
} | } | ||||
$location = phutil_tag( | $location = phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => $href, | 'href' => $href, | ||||
), | ), | ||||
$file.':'.$line); | $location); | ||||
} else if ($file) { | |||||
$location = $file.':'.$line; | |||||
} else { | |||||
$location = '?'; | |||||
} | |||||
$rows[] = array( | $rows[] = array( | ||||
$symbol->getSymbolType(), | $symbol->getSymbolType(), | ||||
$symbol->getSymbolContext(), | $symbol->getSymbolContext(), | ||||
$symbol->getSymbolName(), | $symbol->getSymbolName(), | ||||
$symbol->getSymbolLanguage(), | $symbol->getSymbolLanguage(), | ||||
$repo->getMonogram(), | $source, | ||||
$location, | $location, | ||||
); | ); | ||||
} | } | ||||
$table = new AphrontTableView($rows); | $table = new AphrontTableView($rows); | ||||
$table->setHeaders( | $table->setHeaders( | ||||
array( | array( | ||||
pht('Type'), | pht('Type'), | ||||
pht('Context'), | pht('Context'), | ||||
pht('Name'), | pht('Name'), | ||||
pht('Language'), | pht('Language'), | ||||
pht('Repository'), | pht('Source'), | ||||
pht('File'), | pht('Location'), | ||||
)); | )); | ||||
$table->setColumnClasses( | $table->setColumnClasses( | ||||
array( | array( | ||||
'', | '', | ||||
'', | '', | ||||
'pri', | 'pri', | ||||
'', | '', | ||||
'', | '', | ||||
Show All 17 Lines |
I wanted to explicitly have the indexed results first, but maybe the built-ins should go first, in case we have lots of the indexed ones?