3 final class PhabricatorConduitMethodQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
9 private $applicationNames;
10 private $nameContains;
14 public function withMethods(array $methods) {
15 $this->methods
= $methods;
19 public function withNameContains($name_contains) {
20 $this->nameContains
= $name_contains;
24 public function withIsStable($is_stable) {
25 $this->isStable
= $is_stable;
29 public function withIsUnstable($is_unstable) {
30 $this->isUnstable
= $is_unstable;
34 public function withIsDeprecated($is_deprecated) {
35 $this->isDeprecated
= $is_deprecated;
39 public function withIsInternal($is_internal) {
40 $this->isInternal
= $is_internal;
44 protected function loadPage() {
45 $methods = $this->getAllMethods();
46 $methods = $this->filterMethods($methods);
50 private function getAllMethods() {
51 return id(new PhutilClassMapQuery())
52 ->setAncestorClass('ConduitAPIMethod')
53 ->setSortMethod('getSortOrder')
57 private function filterMethods(array $methods) {
58 foreach ($methods as $key => $method) {
59 $application = $method->getApplication();
63 if (!$application->isInstalled()) {
64 unset($methods[$key]);
69 ConduitAPIMethod
::METHOD_STATUS_STABLE
=> $this->isStable
,
70 ConduitAPIMethod
::METHOD_STATUS_FROZEN
=> $this->isStable
,
71 ConduitAPIMethod
::METHOD_STATUS_DEPRECATED
=> $this->isDeprecated
,
72 ConduitAPIMethod
::METHOD_STATUS_UNSTABLE
=> $this->isUnstable
,
75 // Only apply status filters if any of them are set.
76 if (array_filter($status)) {
77 foreach ($methods as $key => $method) {
78 $keep = idx($status, $method->getMethodStatus());
80 unset($methods[$key]);
85 if ($this->nameContains
) {
86 $needle = phutil_utf8_strtolower($this->nameContains
);
87 foreach ($methods as $key => $method) {
88 $haystack = $method->getAPIMethodName();
89 $haystack = phutil_utf8_strtolower($haystack);
90 if (strpos($haystack, $needle) === false) {
91 unset($methods[$key]);
97 $map = array_fuse($this->methods
);
98 foreach ($methods as $key => $method) {
99 $needle = $method->getAPIMethodName();
100 if (empty($map[$needle])) {
101 unset($methods[$key]);
106 if ($this->isInternal
!== null) {
107 foreach ($methods as $key => $method) {
108 if ($method->isInternalAPI() !== $this->isInternal
) {
109 unset($methods[$key]);
117 protected function willFilterPage(array $methods) {
118 $application_phids = array();
119 foreach ($methods as $method) {
120 $application = $method->getApplication();
121 if ($application === null) {
124 $application_phids[] = $application->getPHID();
127 if ($application_phids) {
128 $applications = id(new PhabricatorApplicationQuery())
129 ->setParentQuery($this)
130 ->setViewer($this->getViewer())
131 ->withPHIDs($application_phids)
133 $applications = mpull($applications, null, 'getPHID');
135 $applications = array();
138 // Remove methods which belong to an application the viewer can not see.
139 foreach ($methods as $key => $method) {
140 $application = $method->getApplication();
141 if ($application === null) {
145 if (empty($applications[$application->getPHID()])) {
146 $this->didRejectResult($method);
147 unset($methods[$key]);
154 public function getQueryApplicationClass() {
155 return 'PhabricatorConduitApplication';