Path: blob/master/src/applications/conduit/query/PhabricatorConduitMethodQuery.php
12262 views
<?php12final class PhabricatorConduitMethodQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $isDeprecated;6private $isStable;7private $isUnstable;8private $applicationNames;9private $nameContains;10private $methods;11private $isInternal;1213public function withMethods(array $methods) {14$this->methods = $methods;15return $this;16}1718public function withNameContains($name_contains) {19$this->nameContains = $name_contains;20return $this;21}2223public function withIsStable($is_stable) {24$this->isStable = $is_stable;25return $this;26}2728public function withIsUnstable($is_unstable) {29$this->isUnstable = $is_unstable;30return $this;31}3233public function withIsDeprecated($is_deprecated) {34$this->isDeprecated = $is_deprecated;35return $this;36}3738public function withIsInternal($is_internal) {39$this->isInternal = $is_internal;40return $this;41}4243protected function loadPage() {44$methods = $this->getAllMethods();45$methods = $this->filterMethods($methods);46return $methods;47}4849private function getAllMethods() {50return id(new PhutilClassMapQuery())51->setAncestorClass('ConduitAPIMethod')52->setSortMethod('getSortOrder')53->execute();54}5556private function filterMethods(array $methods) {57foreach ($methods as $key => $method) {58$application = $method->getApplication();59if (!$application) {60continue;61}62if (!$application->isInstalled()) {63unset($methods[$key]);64}65}6667$status = array(68ConduitAPIMethod::METHOD_STATUS_STABLE => $this->isStable,69ConduitAPIMethod::METHOD_STATUS_FROZEN => $this->isStable,70ConduitAPIMethod::METHOD_STATUS_DEPRECATED => $this->isDeprecated,71ConduitAPIMethod::METHOD_STATUS_UNSTABLE => $this->isUnstable,72);7374// Only apply status filters if any of them are set.75if (array_filter($status)) {76foreach ($methods as $key => $method) {77$keep = idx($status, $method->getMethodStatus());78if (!$keep) {79unset($methods[$key]);80}81}82}8384if ($this->nameContains) {85$needle = phutil_utf8_strtolower($this->nameContains);86foreach ($methods as $key => $method) {87$haystack = $method->getAPIMethodName();88$haystack = phutil_utf8_strtolower($haystack);89if (strpos($haystack, $needle) === false) {90unset($methods[$key]);91}92}93}9495if ($this->methods) {96$map = array_fuse($this->methods);97foreach ($methods as $key => $method) {98$needle = $method->getAPIMethodName();99if (empty($map[$needle])) {100unset($methods[$key]);101}102}103}104105if ($this->isInternal !== null) {106foreach ($methods as $key => $method) {107if ($method->isInternalAPI() !== $this->isInternal) {108unset($methods[$key]);109}110}111}112113return $methods;114}115116protected function willFilterPage(array $methods) {117$application_phids = array();118foreach ($methods as $method) {119$application = $method->getApplication();120if ($application === null) {121continue;122}123$application_phids[] = $application->getPHID();124}125126if ($application_phids) {127$applications = id(new PhabricatorApplicationQuery())128->setParentQuery($this)129->setViewer($this->getViewer())130->withPHIDs($application_phids)131->execute();132$applications = mpull($applications, null, 'getPHID');133} else {134$applications = array();135}136137// Remove methods which belong to an application the viewer can not see.138foreach ($methods as $key => $method) {139$application = $method->getApplication();140if ($application === null) {141continue;142}143144if (empty($applications[$application->getPHID()])) {145$this->didRejectResult($method);146unset($methods[$key]);147}148}149150return $methods;151}152153public function getQueryApplicationClass() {154return 'PhabricatorConduitApplication';155}156157}158159160