1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-16 03:42:41 +01:00
phorge-phorge/src/applications/conduit/controller/PhabricatorConduitConsoleController.php

138 lines
3.9 KiB
PHP
Raw Normal View History

2011-01-24 18:00:29 +01:00
<?php
final class PhabricatorConduitConsoleController
2011-01-24 18:00:29 +01:00
extends PhabricatorConduitController {
private $method;
public function shouldAllowPublic() {
return true;
}
2011-01-24 18:00:29 +01:00
public function willProcessRequest(array $data) {
$this->method = $data['method'];
2011-01-24 18:00:29 +01:00
}
public function processRequest() {
2011-01-31 03:52:29 +01:00
$request = $this->getRequest();
$viewer = $request->getUser();
2011-01-31 03:52:29 +01:00
$method = id(new PhabricatorConduitMethodQuery())
->setViewer($viewer)
->withMethods(array($this->method))
->executeOne();
if (!$method) {
return new Aphront404Response();
2011-01-24 18:00:29 +01:00
}
$can_call_method = false;
$status = $method->getMethodStatus();
$reason = $method->getMethodStatusDescription();
$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;
}
2011-01-24 18:00:29 +01:00
$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);
2011-01-24 18:00:29 +01:00
}
$error_description = phutil_tag('ul', array(), $error_description);
2011-01-24 18:00:29 +01:00
$form = new AphrontFormView();
$form
2011-01-31 03:52:29 +01:00
->setUser($request->getUser())
2011-01-24 18:00:29 +01:00
->setAction('/api/'.$this->method)
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Description')
->setValue($method->getMethodDescription()))
2011-01-24 18:00:29 +01:00
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Returns')
->setValue($method->getReturnType()))
2011-01-24 18:00:29 +01:00
->appendChild(
2011-01-24 20:36:53 +01:00
id(new AphrontFormMarkupControl())
2011-01-24 18:00:29 +01:00
->setLabel('Errors')
->setValue($error_description))
->appendChild(hsprintf(
2011-01-24 18:00:29 +01:00
'<p class="aphront-form-instructions">Enter parameters using '.
'<strong>JSON</strong>. For instance, to enter a list, type: '.
'<tt>["apple", "banana", "cherry"]</tt>'));
2011-01-24 18:00:29 +01: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}]")
->setCaption($desc));
2011-01-24 18:00:29 +01: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
$form_box = id(new PHUIObjectBoxView())
->setHeader($header)
->setFormErrors($errors)
->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($method->getAPIMethodName());
2011-01-24 18:00:29 +01:00
return $this->buildApplicationPage(
array(
$crumbs,
$form_box,
),
2011-01-24 18:00:29 +01:00
array(
'title' => $method->getAPIMethodName(),
2011-01-24 18:00:29 +01:00
));
}
}