2011-01-24 18:00:29 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorConduitConsoleController
|
2011-01-24 18:00:29 +01:00
|
|
|
extends PhabricatorConduitController {
|
|
|
|
|
2014-04-22 00:32:48 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-08 21:19:52 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$method_name = $request->getURIData('method');
|
2011-01-31 03:52:29 +01:00
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
$method = id(new PhabricatorConduitMethodQuery())
|
|
|
|
->setViewer($viewer)
|
2015-05-08 21:19:52 +02:00
|
|
|
->withMethods(array($method_name))
|
2013-07-01 21:36:34 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$method) {
|
2012-04-27 07:25:05 +02:00
|
|
|
return new Aphront404Response();
|
2011-01-24 18:00:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-08 21:19:52 +02:00
|
|
|
$call_uri = '/api/'.$method->getAPIMethodName();
|
2014-04-22 00:32:48 +02:00
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
$status = $method->getMethodStatus();
|
|
|
|
$reason = $method->getMethodStatusDescription();
|
2014-04-22 00:32:48 +02:00
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
switch ($status) {
|
|
|
|
case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
|
|
|
|
$reason = nonempty($reason, pht('This method is deprecated.'));
|
|
|
|
$errors[] = pht('Deprecated Method: %s', $reason);
|
|
|
|
break;
|
|
|
|
case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
|
|
|
|
$reason = nonempty(
|
|
|
|
$reason,
|
|
|
|
pht(
|
|
|
|
'This method is new and unstable. Its interface is subject '.
|
|
|
|
'to change.'));
|
|
|
|
$errors[] = pht('Unstable Method: %s', $reason);
|
|
|
|
break;
|
2012-04-18 23:25:27 +02:00
|
|
|
}
|
2011-01-24 18:00:29 +01:00
|
|
|
|
2015-05-08 21:19:52 +02:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setAction($call_uri)
|
2011-01-31 03:52:29 +01:00
|
|
|
->setUser($request->getUser())
|
2015-05-08 21:19:52 +02:00
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'Enter parameters using **JSON**. For instance, to enter a '.
|
|
|
|
'list, type: `["apple", "banana", "cherry"]`'));
|
2011-01-24 18:00:29 +01:00
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
$params = $method->getParamTypes();
|
2011-01-24 18:00:29 +01:00
|
|
|
foreach ($params as $param => $desc) {
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel($param)
|
|
|
|
->setName("params[{$param}]")
|
2013-02-05 22:23:05 +01:00
|
|
|
->setCaption($desc));
|
2011-01-24 18:00:29 +01:00
|
|
|
}
|
|
|
|
|
2014-04-22 00:32:48 +02:00
|
|
|
$must_login = !$viewer->isLoggedIn() &&
|
|
|
|
$method->shouldRequireAuthentication();
|
|
|
|
if ($must_login) {
|
|
|
|
$errors[] = pht(
|
|
|
|
'Login Required: This method requires authentication. You must '.
|
|
|
|
'log in before you can make calls to it.');
|
|
|
|
} else {
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel('Output Format')
|
|
|
|
->setName('output')
|
|
|
|
->setOptions(
|
|
|
|
array(
|
|
|
|
'human' => 'Human Readable',
|
|
|
|
'json' => 'JSON',
|
|
|
|
)))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton($this->getApplicationURI())
|
|
|
|
->setValue(pht('Call Method')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setHeader($method->getAPIMethodName());
|
2011-01-24 18:00:29 +01:00
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2015-05-08 21:19:52 +02:00
|
|
|
->setHeaderText(pht('Call Method'))
|
2015-04-13 01:26:57 +02:00
|
|
|
->appendChild($form);
|
|
|
|
|
|
|
|
$content = array();
|
|
|
|
|
2015-05-08 21:19:52 +02:00
|
|
|
$properties = $this->buildMethodProperties($method);
|
|
|
|
|
|
|
|
$info_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('API Method: %s', $method->getAPIMethodName()))
|
|
|
|
->setFormErrors($errors)
|
|
|
|
->appendChild($properties);
|
|
|
|
|
|
|
|
$content[] = $info_box;
|
|
|
|
$content[] = $form_box;
|
|
|
|
$content[] = $this->renderExampleBox($method, null);
|
|
|
|
|
2015-04-13 01:26:57 +02:00
|
|
|
$query = $method->newQueryObject();
|
|
|
|
if ($query) {
|
|
|
|
$orders = $query->getBuiltinOrders();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($orders as $key => $order) {
|
|
|
|
$rows[] = array(
|
|
|
|
$key,
|
|
|
|
$order['name'],
|
|
|
|
implode(', ', $order['vector']),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setHeaders(
|
|
|
|
array(
|
|
|
|
pht('Key'),
|
|
|
|
pht('Description'),
|
|
|
|
pht('Columns'),
|
|
|
|
))
|
|
|
|
->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'pri',
|
|
|
|
'',
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
$content[] = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Builtin Orders'))
|
|
|
|
->appendChild($table);
|
|
|
|
|
|
|
|
$columns = $query->getOrderableColumns();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($columns as $key => $column) {
|
|
|
|
$rows[] = array(
|
|
|
|
$key,
|
|
|
|
idx($column, 'unique') ? pht('Yes') : pht('No'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setHeaders(
|
|
|
|
array(
|
|
|
|
pht('Key'),
|
|
|
|
pht('Unique'),
|
|
|
|
))
|
|
|
|
->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'pri',
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
$content[] = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Column Orders'))
|
|
|
|
->appendChild($table);
|
|
|
|
}
|
2013-08-27 00:45:58 +02:00
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb($method->getAPIMethodName());
|
2011-01-24 18:00:29 +01:00
|
|
|
|
2013-07-01 21:36:34 +02:00
|
|
|
return $this->buildApplicationPage(
|
2012-04-18 23:25:27 +02:00
|
|
|
array(
|
2013-07-01 21:36:34 +02:00
|
|
|
$crumbs,
|
2015-04-13 01:26:57 +02:00
|
|
|
$content,
|
2012-04-18 23:25:27 +02:00
|
|
|
),
|
2011-01-24 18:00:29 +01:00
|
|
|
array(
|
2013-07-01 21:36:34 +02:00
|
|
|
'title' => $method->getAPIMethodName(),
|
2011-01-24 18:00:29 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-05-08 21:19:52 +02:00
|
|
|
private function buildMethodProperties(ConduitAPIMethod $method) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$view = id(new PHUIPropertyListView());
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Returns'),
|
|
|
|
$method->getReturnType());
|
|
|
|
|
|
|
|
$error_types = $method->getErrorTypes();
|
|
|
|
$error_types['ERR-CONDUIT-CORE'] = pht('See error message for details.');
|
|
|
|
$error_description = array();
|
|
|
|
foreach ($error_types as $error => $meaning) {
|
|
|
|
$error_description[] = hsprintf(
|
|
|
|
'<li><strong>%s:</strong> %s</li>',
|
|
|
|
$error,
|
|
|
|
$meaning);
|
|
|
|
}
|
|
|
|
$error_description = phutil_tag('ul', array(), $error_description);
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Errors'),
|
|
|
|
$error_description);
|
|
|
|
|
|
|
|
|
|
|
|
$description = $method->getMethodDescription();
|
|
|
|
$description = PhabricatorMarkupEngine::renderOneObject(
|
|
|
|
id(new PhabricatorMarkupOneOff())->setContent($description),
|
|
|
|
'default',
|
|
|
|
$viewer);
|
|
|
|
$view->addSectionHeader(pht('Description'));
|
|
|
|
$view->addTextContent($description);
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-24 18:00:29 +01:00
|
|
|
}
|