@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 178 lines 4.2 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorApplication> 5 */ 6final class PhabricatorApplicationQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $installed; 10 private $prototypes; 11 private $firstParty; 12 private $nameContains; 13 private $unlisted; 14 private $classes; 15 private $launchable; 16 private $applicationEmailSupport; 17 private $phids; 18 19 const ORDER_APPLICATION = 'order:application'; 20 const ORDER_NAME = 'order:name'; 21 22 private $order = self::ORDER_APPLICATION; 23 24 public function withNameContains($name_contains) { 25 $this->nameContains = $name_contains; 26 return $this; 27 } 28 29 public function withInstalled($installed) { 30 $this->installed = $installed; 31 return $this; 32 } 33 34 public function withPrototypes($prototypes) { 35 $this->prototypes = $prototypes; 36 return $this; 37 } 38 39 public function withFirstParty($first_party) { 40 $this->firstParty = $first_party; 41 return $this; 42 } 43 44 public function withUnlisted($unlisted) { 45 $this->unlisted = $unlisted; 46 return $this; 47 } 48 49 public function withLaunchable($launchable) { 50 $this->launchable = $launchable; 51 return $this; 52 } 53 54 public function withApplicationEmailSupport($appemails) { 55 $this->applicationEmailSupport = $appemails; 56 return $this; 57 } 58 59 /** 60 * @param array<class-string<PhabricatorApplication>> $classes 61 */ 62 public function withClasses(array $classes) { 63 $this->classes = $classes; 64 return $this; 65 } 66 67 public function withPHIDs(array $phids) { 68 $this->phids = $phids; 69 return $this; 70 } 71 72 public function setOrder($order) { 73 $this->order = $order; 74 return $this; 75 } 76 77 protected function loadPage() { 78 $apps = PhabricatorApplication::getAllApplications(); 79 80 if ($this->classes) { 81 $classes = array_fuse($this->classes); 82 foreach ($apps as $key => $app) { 83 if (empty($classes[get_class($app)])) { 84 unset($apps[$key]); 85 } 86 } 87 } 88 89 if ($this->phids) { 90 $phids = array_fuse($this->phids); 91 foreach ($apps as $key => $app) { 92 if (empty($phids[$app->getPHID()])) { 93 unset($apps[$key]); 94 } 95 } 96 } 97 98 if ($this->nameContains !== null) { 99 foreach ($apps as $key => $app) { 100 if (stripos($app->getName(), $this->nameContains) === false) { 101 unset($apps[$key]); 102 } 103 } 104 } 105 106 if ($this->installed !== null) { 107 foreach ($apps as $key => $app) { 108 if ($app->isInstalled() != $this->installed) { 109 unset($apps[$key]); 110 } 111 } 112 } 113 114 if ($this->prototypes !== null) { 115 foreach ($apps as $key => $app) { 116 if ($app->isPrototype() != $this->prototypes) { 117 unset($apps[$key]); 118 } 119 } 120 } 121 122 if ($this->firstParty !== null) { 123 foreach ($apps as $key => $app) { 124 if ($app->isFirstParty() != $this->firstParty) { 125 unset($apps[$key]); 126 } 127 } 128 } 129 130 if ($this->unlisted !== null) { 131 foreach ($apps as $key => $app) { 132 if ($app->isUnlisted() != $this->unlisted) { 133 unset($apps[$key]); 134 } 135 } 136 } 137 138 if ($this->launchable !== null) { 139 foreach ($apps as $key => $app) { 140 if ($app->isLaunchable() != $this->launchable) { 141 unset($apps[$key]); 142 } 143 } 144 } 145 146 if ($this->applicationEmailSupport !== null) { 147 foreach ($apps as $key => $app) { 148 if ($app->supportsEmailIntegration() != 149 $this->applicationEmailSupport) { 150 unset($apps[$key]); 151 } 152 } 153 } 154 155 switch ($this->order) { 156 case self::ORDER_NAME: 157 $apps = msort($apps, 'getName'); 158 break; 159 case self::ORDER_APPLICATION: 160 break; 161 default: 162 throw new Exception( 163 pht('Unknown order "%s"!', $this->order)); 164 } 165 166 return $apps; 167 } 168 169 170 public function getQueryApplicationClass() { 171 // NOTE: Although this belongs to the "Applications" application, trying 172 // to filter its results just leaves us recursing indefinitely. Users 173 // always have access to applications regardless of other policy settings 174 // anyway. 175 return null; 176 } 177 178}