[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorConduitMethodQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $isDeprecated; 7 private $isStable; 8 private $isUnstable; 9 private $applicationNames; 10 private $nameContains; 11 private $methods; 12 13 public function withMethods(array $methods) { 14 $this->methods = $methods; 15 return $this; 16 } 17 18 public function withNameContains($name_contains) { 19 $this->nameContains = $name_contains; 20 return $this; 21 } 22 23 public function withApplicationNames(array $application_names) { 24 $this->applicationNames = $application_names; 25 return $this; 26 } 27 28 public function withIsStable($is_stable) { 29 $this->isStable = $is_stable; 30 return $this; 31 } 32 33 public function withIsUnstable($is_unstable) { 34 $this->isUnstable = $is_unstable; 35 return $this; 36 } 37 38 public function withIsDeprecated($is_deprecated) { 39 $this->isDeprecated = $is_deprecated; 40 return $this; 41 } 42 43 public function loadPage() { 44 $methods = $this->getAllMethods(); 45 $methods = $this->filterMethods($methods); 46 return $methods; 47 } 48 49 private function getAllMethods() { 50 static $methods; 51 if ($methods === null) { 52 $methods = id(new PhutilSymbolLoader()) 53 ->setAncestorClass('ConduitAPIMethod') 54 ->loadObjects(); 55 $methods = msort($methods, 'getSortOrder'); 56 } 57 return $methods; 58 } 59 60 private function filterMethods(array $methods) { 61 foreach ($methods as $key => $method) { 62 $application = $method->getApplication(); 63 if (!$application) { 64 continue; 65 } 66 if (!$application->isInstalled()) { 67 unset($methods[$key]); 68 } 69 } 70 71 $status = array( 72 ConduitAPIMethod::METHOD_STATUS_STABLE => $this->isStable, 73 ConduitAPIMethod::METHOD_STATUS_DEPRECATED => $this->isDeprecated, 74 ConduitAPIMethod::METHOD_STATUS_UNSTABLE => $this->isUnstable, 75 ); 76 77 // Only apply status filters if any of them are set. 78 if (array_filter($status)) { 79 foreach ($methods as $key => $method) { 80 $keep = idx($status, $method->getMethodStatus()); 81 if (!$keep) { 82 unset($methods[$key]); 83 } 84 } 85 } 86 87 if ($this->applicationNames) { 88 $map = array_fuse($this->applicationNames); 89 foreach ($methods as $key => $method) { 90 $needle = $method->getApplicationName(); 91 $needle = phutil_utf8_strtolower($needle); 92 if (empty($map[$needle])) { 93 unset($methods[$key]); 94 } 95 } 96 } 97 98 if ($this->nameContains) { 99 $needle = phutil_utf8_strtolower($this->nameContains); 100 foreach ($methods as $key => $method) { 101 $haystack = $method->getAPIMethodName(); 102 $haystack = phutil_utf8_strtolower($haystack); 103 if (strpos($haystack, $needle) === false) { 104 unset($methods[$key]); 105 } 106 } 107 } 108 109 if ($this->methods) { 110 $map = array_fuse($this->methods); 111 foreach ($methods as $key => $method) { 112 $needle = $method->getAPIMethodName(); 113 if (empty($map[$needle])) { 114 unset($methods[$key]); 115 } 116 } 117 } 118 119 return $methods; 120 } 121 122 public function getQueryApplicationClass() { 123 return 'PhabricatorConduitApplication'; 124 } 125 126 }
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 |