Path: blob/master/src/applications/meta/query/PhabricatorApplicationQuery.php
12256 views
<?php12final class PhabricatorApplicationQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $installed;6private $prototypes;7private $firstParty;8private $nameContains;9private $unlisted;10private $classes;11private $launchable;12private $applicationEmailSupport;13private $phids;1415const ORDER_APPLICATION = 'order:application';16const ORDER_NAME = 'order:name';1718private $order = self::ORDER_APPLICATION;1920public function withNameContains($name_contains) {21$this->nameContains = $name_contains;22return $this;23}2425public function withInstalled($installed) {26$this->installed = $installed;27return $this;28}2930public function withPrototypes($prototypes) {31$this->prototypes = $prototypes;32return $this;33}3435public function withFirstParty($first_party) {36$this->firstParty = $first_party;37return $this;38}3940public function withUnlisted($unlisted) {41$this->unlisted = $unlisted;42return $this;43}4445public function withLaunchable($launchable) {46$this->launchable = $launchable;47return $this;48}4950public function withApplicationEmailSupport($appemails) {51$this->applicationEmailSupport = $appemails;52return $this;53}5455public function withClasses(array $classes) {56$this->classes = $classes;57return $this;58}5960public function withPHIDs(array $phids) {61$this->phids = $phids;62return $this;63}6465public function setOrder($order) {66$this->order = $order;67return $this;68}6970protected function loadPage() {71$apps = PhabricatorApplication::getAllApplications();7273if ($this->classes) {74$classes = array_fuse($this->classes);75foreach ($apps as $key => $app) {76if (empty($classes[get_class($app)])) {77unset($apps[$key]);78}79}80}8182if ($this->phids) {83$phids = array_fuse($this->phids);84foreach ($apps as $key => $app) {85if (empty($phids[$app->getPHID()])) {86unset($apps[$key]);87}88}89}9091if ($this->nameContains !== null) {92foreach ($apps as $key => $app) {93if (stripos($app->getName(), $this->nameContains) === false) {94unset($apps[$key]);95}96}97}9899if ($this->installed !== null) {100foreach ($apps as $key => $app) {101if ($app->isInstalled() != $this->installed) {102unset($apps[$key]);103}104}105}106107if ($this->prototypes !== null) {108foreach ($apps as $key => $app) {109if ($app->isPrototype() != $this->prototypes) {110unset($apps[$key]);111}112}113}114115if ($this->firstParty !== null) {116foreach ($apps as $key => $app) {117if ($app->isFirstParty() != $this->firstParty) {118unset($apps[$key]);119}120}121}122123if ($this->unlisted !== null) {124foreach ($apps as $key => $app) {125if ($app->isUnlisted() != $this->unlisted) {126unset($apps[$key]);127}128}129}130131if ($this->launchable !== null) {132foreach ($apps as $key => $app) {133if ($app->isLaunchable() != $this->launchable) {134unset($apps[$key]);135}136}137}138139if ($this->applicationEmailSupport !== null) {140foreach ($apps as $key => $app) {141if ($app->supportsEmailIntegration() !=142$this->applicationEmailSupport) {143unset($apps[$key]);144}145}146}147148switch ($this->order) {149case self::ORDER_NAME:150$apps = msort($apps, 'getName');151break;152case self::ORDER_APPLICATION:153$apps = $apps;154break;155default:156throw new Exception(157pht('Unknown order "%s"!', $this->order));158}159160return $apps;161}162163164public function getQueryApplicationClass() {165// NOTE: Although this belongs to the "Applications" application, trying166// to filter its results just leaves us recursing indefinitely. Users167// always have access to applications regardless of other policy settings168// anyway.169return null;170}171172}173174175