[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorConduitSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Conduit Methods'); 8 } 9 10 public function getApplicationClassName() { 11 return 'PhabricatorConduitApplication'; 12 } 13 14 public function getPageSize(PhabricatorSavedQuery $saved) { 15 return PHP_INT_MAX - 1; 16 } 17 18 public function buildSavedQueryFromRequest(AphrontRequest $request) { 19 $saved = new PhabricatorSavedQuery(); 20 21 $saved->setParameter('isStable', $request->getStr('isStable')); 22 $saved->setParameter('isUnstable', $request->getStr('isUnstable')); 23 $saved->setParameter('isDeprecated', $request->getStr('isDeprecated')); 24 25 $saved->setParameter( 26 'applicationNames', 27 $request->getStrList('applicationNames')); 28 29 $saved->setParameter('nameContains', $request->getStr('nameContains')); 30 31 return $saved; 32 } 33 34 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 35 $query = id(new PhabricatorConduitMethodQuery()); 36 37 $query->withIsStable($saved->getParameter('isStable')); 38 $query->withIsUnstable($saved->getParameter('isUnstable')); 39 $query->withIsDeprecated($saved->getParameter('isDeprecated')); 40 41 $names = $saved->getParameter('applicationNames', array()); 42 if ($names) { 43 $query->withApplicationNames($names); 44 } 45 46 $contains = $saved->getParameter('nameContains'); 47 if (strlen($contains)) { 48 $query->withNameContains($contains); 49 } 50 51 return $query; 52 } 53 54 public function buildSearchForm( 55 AphrontFormView $form, 56 PhabricatorSavedQuery $saved) { 57 58 $form 59 ->appendChild( 60 id(new AphrontFormTextControl()) 61 ->setLabel('Name Contains') 62 ->setName('nameContains') 63 ->setValue($saved->getParameter('nameContains'))); 64 65 $names = $saved->getParameter('applicationNames', array()); 66 $form 67 ->appendChild( 68 id(new AphrontFormTextControl()) 69 ->setLabel('Applications') 70 ->setName('applicationNames') 71 ->setValue(implode(', ', $names)) 72 ->setCaption(pht( 73 'Example: %s', 74 phutil_tag('tt', array(), 'differential, paste')))); 75 76 $is_stable = $saved->getParameter('isStable'); 77 $is_unstable = $saved->getParameter('isUnstable'); 78 $is_deprecated = $saved->getParameter('isDeprecated'); 79 $form 80 ->appendChild( 81 id(new AphrontFormCheckboxControl()) 82 ->setLabel('Stability') 83 ->addCheckbox( 84 'isStable', 85 1, 86 hsprintf( 87 '<strong>%s</strong>: %s', 88 pht('Stable Methods'), 89 pht('Show established API methods with stable interfaces.')), 90 $is_stable) 91 ->addCheckbox( 92 'isUnstable', 93 1, 94 hsprintf( 95 '<strong>%s</strong>: %s', 96 pht('Unstable Methods'), 97 pht('Show new methods which are subject to change.')), 98 $is_unstable) 99 ->addCheckbox( 100 'isDeprecated', 101 1, 102 hsprintf( 103 '<strong>%s</strong>: %s', 104 pht('Deprecated Methods'), 105 pht( 106 'Show old methods which will be deleted in a future '. 107 'version of Phabricator.')), 108 $is_deprecated)); 109 } 110 111 protected function getURI($path) { 112 return '/conduit/'.$path; 113 } 114 115 public function getBuiltinQueryNames() { 116 return array( 117 'modern' => pht('Modern Methods'), 118 'all' => pht('All Methods'), 119 ); 120 } 121 122 public function buildSavedQueryFromBuiltin($query_key) { 123 $query = $this->newSavedQuery(); 124 $query->setQueryKey($query_key); 125 126 switch ($query_key) { 127 case 'modern': 128 return $query 129 ->setParameter('isStable', true) 130 ->setParameter('isUnstable', true); 131 case 'all': 132 return $query 133 ->setParameter('isStable', true) 134 ->setParameter('isUnstable', true) 135 ->setParameter('isDeprecated', true); 136 } 137 138 return parent::buildSavedQueryFromBuiltin($query_key); 139 } 140 141 protected function renderResultList( 142 array $methods, 143 PhabricatorSavedQuery $query, 144 array $handles) { 145 assert_instances_of($methods, 'ConduitAPIMethod'); 146 147 $viewer = $this->requireViewer(); 148 149 $out = array(); 150 151 $last = null; 152 $list = null; 153 foreach ($methods as $method) { 154 $app = $method->getApplicationName(); 155 if ($app !== $last) { 156 $last = $app; 157 if ($list) { 158 $out[] = $list; 159 } 160 $list = id(new PHUIObjectItemListView()); 161 162 $app_object = $method->getApplication(); 163 if ($app_object) { 164 $app_name = $app_object->getName(); 165 } else { 166 $app_name = $app; 167 } 168 } 169 170 $method_name = $method->getAPIMethodName(); 171 172 $item = id(new PHUIObjectItemView()) 173 ->setHeader($method_name) 174 ->setHref($this->getApplicationURI('method/'.$method_name.'/')) 175 ->addAttribute($method->getMethodDescription()); 176 177 switch ($method->getMethodStatus()) { 178 case ConduitAPIMethod::METHOD_STATUS_STABLE: 179 break; 180 case ConduitAPIMethod::METHOD_STATUS_UNSTABLE: 181 $item->addIcon('warning-grey', pht('Unstable')); 182 $item->setBarColor('yellow'); 183 break; 184 case ConduitAPIMethod::METHOD_STATUS_DEPRECATED: 185 $item->addIcon('warning', pht('Deprecated')); 186 $item->setBarColor('red'); 187 break; 188 } 189 190 $list->addItem($item); 191 } 192 193 if ($list) { 194 $out[] = $list; 195 } 196 197 return $out; 198 } 199 200 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |