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