1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-04 04:32:43 +01:00
phorge-phorge/src/applications/diffusion/conduit/DiffusionFindSymbolsConduitAPIMethod.php
epriestley 156b156e77 Give Conduit params/return/errors protected visibility
Summary:
Ref T7803. Ref T5873. I want to drive Conduit through more shared infrastructure, but can't currently add parameters automatically.

Put a `getX()` around the `defineX()` methods so the parent can provide default behaviors.

Also like 60% of methods don't define any special error types; don't require them to implement this method. I want to move away from this in general.

Test Plan:
  - Ran `arc unit --everything`.
  - Called `conduit.query`.
  - Browsed Conduit UI.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: hach-que, epriestley

Maniphest Tasks: T5873, T7803

Differential Revision: https://secure.phabricator.com/D12380
2015-04-13 11:58:35 -07:00

81 lines
2 KiB
PHP

<?php
final class DiffusionFindSymbolsConduitAPIMethod
extends DiffusionConduitAPIMethod {
public function getAPIMethodName() {
return 'diffusion.findsymbols';
}
public function getMethodDescription() {
return 'Retrieve Diffusion symbol information.';
}
protected function defineParamTypes() {
return array(
'name' => 'optional string',
'namePrefix' => 'optional string',
'context' => 'optional string',
'language' => 'optional string',
'type' => 'optional string',
);
}
protected function defineReturnType() {
return 'nonempty list<dict>';
}
protected function execute(ConduitAPIRequest $request) {
$name = $request->getValue('name');
$name_prefix = $request->getValue('namePrefix');
$context = $request->getValue('context');
$language = $request->getValue('language');
$type = $request->getValue('type');
$query = id(new DiffusionSymbolQuery())
->setViewer($request->getUser());
if ($name !== null) {
$query->setName($name);
}
if ($name_prefix !== null) {
$query->setNamePrefix($name_prefix);
}
if ($context !== null) {
$query->setContext($context);
}
if ($language !== null) {
$query->setLanguage($language);
}
if ($type !== null) {
$query->setType($type);
}
$query->needPaths(true);
$query->needArcanistProjects(true);
$query->needRepositories(true);
$results = $query->execute();
$response = array();
foreach ($results as $result) {
$uri = $result->getURI();
if ($uri) {
$uri = PhabricatorEnv::getProductionURI($uri);
}
$response[] = array(
'name' => $result->getSymbolName(),
'context' => $result->getSymbolContext(),
'type' => $result->getSymbolType(),
'language' => $result->getSymbolLanguage(),
'path' => $result->getPath(),
'line' => $result->getLineNumber(),
'uri' => $uri,
);
}
return $response;
}
}