Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conduit/query/PhabricatorConduitSearchEngine.php
12256 views
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 canUseInPanelContext() {
15
return false;
16
}
17
18
public function getPageSize(PhabricatorSavedQuery $saved) {
19
return PHP_INT_MAX - 1;
20
}
21
22
public function buildSavedQueryFromRequest(AphrontRequest $request) {
23
$saved = new PhabricatorSavedQuery();
24
25
$saved->setParameter('isStable', $request->getStr('isStable'));
26
$saved->setParameter('isUnstable', $request->getStr('isUnstable'));
27
$saved->setParameter('isDeprecated', $request->getStr('isDeprecated'));
28
$saved->setParameter('nameContains', $request->getStr('nameContains'));
29
30
return $saved;
31
}
32
33
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
34
$query = id(new PhabricatorConduitMethodQuery());
35
36
$query->withIsStable($saved->getParameter('isStable'));
37
$query->withIsUnstable($saved->getParameter('isUnstable'));
38
$query->withIsDeprecated($saved->getParameter('isDeprecated'));
39
$query->withIsInternal(false);
40
41
$contains = $saved->getParameter('nameContains');
42
if ($contains !== null && strlen($contains)) {
43
$query->withNameContains($contains);
44
}
45
46
return $query;
47
}
48
49
public function buildSearchForm(
50
AphrontFormView $form,
51
PhabricatorSavedQuery $saved) {
52
53
$form
54
->appendChild(
55
id(new AphrontFormTextControl())
56
->setLabel(pht('Name Contains'))
57
->setName('nameContains')
58
->setValue($saved->getParameter('nameContains')));
59
60
$is_stable = $saved->getParameter('isStable');
61
$is_unstable = $saved->getParameter('isUnstable');
62
$is_deprecated = $saved->getParameter('isDeprecated');
63
$form
64
->appendChild(
65
id(new AphrontFormCheckboxControl())
66
->setLabel('Stability')
67
->addCheckbox(
68
'isStable',
69
1,
70
hsprintf(
71
'<strong>%s</strong>: %s',
72
pht('Stable Methods'),
73
pht('Show established API methods with stable interfaces.')),
74
$is_stable)
75
->addCheckbox(
76
'isUnstable',
77
1,
78
hsprintf(
79
'<strong>%s</strong>: %s',
80
pht('Unstable Methods'),
81
pht('Show new methods which are subject to change.')),
82
$is_unstable)
83
->addCheckbox(
84
'isDeprecated',
85
1,
86
hsprintf(
87
'<strong>%s</strong>: %s',
88
pht('Deprecated Methods'),
89
pht(
90
'Show old methods which will be deleted in a future '.
91
'version of this software.')),
92
$is_deprecated));
93
}
94
95
protected function getURI($path) {
96
return '/conduit/'.$path;
97
}
98
99
protected function getBuiltinQueryNames() {
100
return array(
101
'modern' => pht('Modern Methods'),
102
'all' => pht('All Methods'),
103
);
104
}
105
106
public function buildSavedQueryFromBuiltin($query_key) {
107
$query = $this->newSavedQuery();
108
$query->setQueryKey($query_key);
109
110
switch ($query_key) {
111
case 'modern':
112
return $query
113
->setParameter('isStable', true)
114
->setParameter('isUnstable', true);
115
case 'all':
116
return $query
117
->setParameter('isStable', true)
118
->setParameter('isUnstable', true)
119
->setParameter('isDeprecated', true);
120
}
121
122
return parent::buildSavedQueryFromBuiltin($query_key);
123
}
124
125
protected function renderResultList(
126
array $methods,
127
PhabricatorSavedQuery $query,
128
array $handles) {
129
assert_instances_of($methods, 'ConduitAPIMethod');
130
131
$viewer = $this->requireViewer();
132
133
$out = array();
134
135
$last = null;
136
$list = null;
137
foreach ($methods as $method) {
138
$app = $method->getApplicationName();
139
if ($app !== $last) {
140
$last = $app;
141
if ($list) {
142
$out[] = $list;
143
}
144
$list = id(new PHUIObjectItemListView());
145
$list->setHeader($app);
146
147
$app_object = $method->getApplication();
148
if ($app_object) {
149
$app_name = $app_object->getName();
150
} else {
151
$app_name = $app;
152
}
153
}
154
155
$method_name = $method->getAPIMethodName();
156
157
$item = id(new PHUIObjectItemView())
158
->setHeader($method_name)
159
->setHref($this->getApplicationURI('method/'.$method_name.'/'))
160
->addAttribute($method->getMethodSummary());
161
162
switch ($method->getMethodStatus()) {
163
case ConduitAPIMethod::METHOD_STATUS_STABLE:
164
break;
165
case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
166
$item->addIcon('fa-warning', pht('Unstable'));
167
$item->setStatusIcon('fa-warning yellow');
168
break;
169
case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
170
$item->addIcon('fa-warning', pht('Deprecated'));
171
$item->setStatusIcon('fa-warning red');
172
break;
173
case ConduitAPIMethod::METHOD_STATUS_FROZEN:
174
$item->addIcon('fa-archive', pht('Frozen'));
175
$item->setStatusIcon('fa-archive grey');
176
break;
177
}
178
179
$list->addItem($item);
180
}
181
182
if ($list) {
183
$out[] = $list;
184
}
185
186
$result = new PhabricatorApplicationSearchResultView();
187
$result->setContent($out);
188
189
return $result;
190
}
191
192
}
193
194