2011-01-24 18:00:29 +01:00
|
|
|
<?php
|
|
|
|
|
2011-07-04 21:03:36 +02:00
|
|
|
/**
|
|
|
|
* @group conduit
|
|
|
|
*/
|
2011-01-24 18:00:29 +01:00
|
|
|
abstract class PhabricatorConduitController extends PhabricatorController {
|
|
|
|
|
2012-01-26 21:47:23 +01:00
|
|
|
private $filter;
|
|
|
|
protected $showSideNav;
|
|
|
|
|
2011-01-24 18:00:29 +01:00
|
|
|
public function buildStandardPageResponse($view, array $data) {
|
2011-01-26 22:21:12 +01:00
|
|
|
$page = $this->buildStandardPageView();
|
2011-01-24 18:00:29 +01:00
|
|
|
|
|
|
|
$page->setApplicationName('Conduit');
|
|
|
|
$page->setBaseURI('/conduit/');
|
|
|
|
$page->setTitle(idx($data, 'title'));
|
|
|
|
$page->setGlyph("\xE2\x87\xB5");
|
2012-01-26 21:47:23 +01:00
|
|
|
|
|
|
|
if ($this->showSideNav()) {
|
|
|
|
|
|
|
|
$nav = new AphrontSideNavFilterView();
|
|
|
|
$nav->setBaseURI(new PhutilURI('/conduit/'));
|
|
|
|
$method_filters = $this->getMethodFilters();
|
|
|
|
foreach ($method_filters as $group => $methods) {
|
|
|
|
$nav->addLabel($group);
|
|
|
|
foreach ($methods as $method) {
|
|
|
|
$method_name = $method['full_name'];
|
2012-04-18 23:25:27 +02:00
|
|
|
|
|
|
|
$display_name = $method_name;
|
|
|
|
switch ($method['status']) {
|
|
|
|
case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
|
|
|
|
$display_name = '('.$display_name.')';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-26 21:47:23 +01:00
|
|
|
$nav->addFilter('method/'.$method_name,
|
2012-04-18 23:25:27 +02:00
|
|
|
$display_name);
|
2012-01-26 21:47:23 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-27 07:25:05 +02:00
|
|
|
$nav->selectFilter($this->getFilter());
|
2012-01-26 21:47:23 +01:00
|
|
|
$nav->appendChild($view);
|
|
|
|
$body = $nav;
|
|
|
|
} else {
|
|
|
|
$body = $view;
|
|
|
|
}
|
|
|
|
$page->appendChild($body);
|
2011-01-24 18:00:29 +01:00
|
|
|
|
|
|
|
$response = new AphrontWebpageResponse();
|
|
|
|
return $response->setContent($page->render());
|
|
|
|
}
|
|
|
|
|
2012-01-26 21:47:23 +01:00
|
|
|
private function getFilter() {
|
|
|
|
return $this->filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setFilter($filter) {
|
|
|
|
$this->filter = $filter;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function showSideNav() {
|
|
|
|
return $this->showSideNav !== false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setShowSideNav($show_side_nav) {
|
|
|
|
$this->showSideNav = $show_side_nav;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getAllMethodImplementationClasses() {
|
|
|
|
$classes = id(new PhutilSymbolLoader())
|
|
|
|
->setAncestorClass('ConduitAPIMethod')
|
|
|
|
->setType('class')
|
|
|
|
->setConcreteOnly(true)
|
|
|
|
->selectSymbolsWithoutLoading();
|
|
|
|
|
|
|
|
return array_values(ipull($classes, 'name'));
|
|
|
|
}
|
|
|
|
|
2012-04-27 07:25:05 +02:00
|
|
|
protected function getMethodFilters() {
|
2012-01-26 21:47:23 +01:00
|
|
|
$classes = $this->getAllMethodImplementationClasses();
|
|
|
|
$method_names = array();
|
|
|
|
foreach ($classes as $method_class) {
|
|
|
|
$method_name = ConduitAPIMethod::getAPIMethodNameFromClassName(
|
|
|
|
$method_class);
|
2012-04-18 23:25:27 +02:00
|
|
|
$group_name = head(explode('.', $method_name));
|
|
|
|
|
2012-04-27 07:25:05 +02:00
|
|
|
$method_object = newv($method_class, array());
|
|
|
|
$status = $method_object->getMethodStatus();
|
2012-04-18 23:25:27 +02:00
|
|
|
|
|
|
|
$key = sprintf(
|
|
|
|
'%02d %s %s',
|
|
|
|
$this->getOrderForMethodStatus($status),
|
|
|
|
$group_name,
|
|
|
|
$method_name);
|
|
|
|
|
|
|
|
$method_names[$key] = array(
|
2012-01-26 21:47:23 +01:00
|
|
|
'full_name' => $method_name,
|
2012-04-18 23:25:27 +02:00
|
|
|
'group_name' => $group_name,
|
|
|
|
'status' => $status,
|
2012-04-27 07:25:05 +02:00
|
|
|
'description' => $method_object->getMethodDescription(),
|
2012-01-26 21:47:23 +01:00
|
|
|
);
|
|
|
|
}
|
2012-04-18 23:25:27 +02:00
|
|
|
ksort($method_names);
|
2012-01-26 21:47:23 +01:00
|
|
|
$method_names = igroup($method_names, 'group_name');
|
|
|
|
ksort($method_names);
|
|
|
|
|
|
|
|
return $method_names;
|
|
|
|
}
|
|
|
|
|
2012-04-18 23:25:27 +02:00
|
|
|
private function getOrderForMethodStatus($status) {
|
|
|
|
$map = array(
|
|
|
|
ConduitAPIMethod::METHOD_STATUS_STABLE => 0,
|
|
|
|
ConduitAPIMethod::METHOD_STATUS_UNSTABLE => 1,
|
|
|
|
ConduitAPIMethod::METHOD_STATUS_DEPRECATED => 2,
|
|
|
|
);
|
|
|
|
return idx($map, $status, 0);
|
|
|
|
}
|
|
|
|
|
2011-01-24 18:00:29 +01:00
|
|
|
}
|