Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/option/PhabricatorConfigOption.php
12256 views
1
<?php
2
3
final class PhabricatorConfigOption
4
extends Phobject {
5
6
private $key;
7
private $default;
8
private $summary;
9
private $description;
10
private $type;
11
private $boolOptions;
12
private $enumOptions;
13
private $group;
14
private $examples;
15
private $locked;
16
private $lockedMessage;
17
private $hidden;
18
private $baseClass;
19
private $customData;
20
private $customObject;
21
22
public function setBaseClass($base_class) {
23
$this->baseClass = $base_class;
24
return $this;
25
}
26
27
public function getBaseClass() {
28
return $this->baseClass;
29
}
30
31
public function setHidden($hidden) {
32
$this->hidden = $hidden;
33
return $this;
34
}
35
36
public function getHidden() {
37
if ($this->hidden) {
38
return true;
39
}
40
41
return idx(
42
PhabricatorEnv::getEnvConfig('config.hide'),
43
$this->getKey(),
44
false);
45
}
46
47
public function setLocked($locked) {
48
$this->locked = $locked;
49
return $this;
50
}
51
52
public function getLocked() {
53
if ($this->locked) {
54
return true;
55
}
56
57
if ($this->getHidden()) {
58
return true;
59
}
60
61
return idx(
62
PhabricatorEnv::getEnvConfig('config.lock'),
63
$this->getKey(),
64
false);
65
}
66
67
public function setLockedMessage($message) {
68
$this->lockedMessage = $message;
69
return $this;
70
}
71
72
public function getLockedMessage() {
73
if ($this->lockedMessage !== null) {
74
return $this->lockedMessage;
75
}
76
return pht(
77
'This configuration is locked and can not be edited from the web '.
78
'interface. Use %s in %s to edit it.',
79
phutil_tag('tt', array(), './bin/config'),
80
phutil_tag('tt', array(), 'phabricator/'));
81
}
82
83
public function addExample($value, $description) {
84
$this->examples[] = array($value, $description);
85
return $this;
86
}
87
88
public function getExamples() {
89
return $this->examples;
90
}
91
92
public function setGroup(PhabricatorApplicationConfigOptions $group) {
93
$this->group = $group;
94
return $this;
95
}
96
97
public function getGroup() {
98
return $this->group;
99
}
100
101
public function setBoolOptions(array $options) {
102
$this->boolOptions = $options;
103
return $this;
104
}
105
106
public function getBoolOptions() {
107
if ($this->boolOptions) {
108
return $this->boolOptions;
109
}
110
return array(
111
pht('True'),
112
pht('False'),
113
);
114
}
115
116
public function setEnumOptions(array $options) {
117
$this->enumOptions = $options;
118
return $this;
119
}
120
121
public function getEnumOptions() {
122
if ($this->enumOptions) {
123
return $this->enumOptions;
124
}
125
126
throw new PhutilInvalidStateException('setEnumOptions');
127
}
128
129
public function setKey($key) {
130
$this->key = $key;
131
return $this;
132
}
133
134
public function getKey() {
135
return $this->key;
136
}
137
138
public function setDefault($default) {
139
$this->default = $default;
140
return $this;
141
}
142
143
public function getDefault() {
144
return $this->default;
145
}
146
147
public function setSummary($summary) {
148
$this->summary = $summary;
149
return $this;
150
}
151
152
public function getSummary() {
153
if (empty($this->summary)) {
154
return $this->getDescription();
155
}
156
return $this->summary;
157
}
158
159
public function setDescription($description) {
160
$this->description = $description;
161
return $this;
162
}
163
164
public function getDescription() {
165
return $this->description;
166
}
167
168
public function setType($type) {
169
$this->type = $type;
170
return $this;
171
}
172
173
public function getType() {
174
return $this->type;
175
}
176
177
public function newOptionType() {
178
$type_key = $this->getType();
179
$type_map = PhabricatorConfigType::getAllTypes();
180
return idx($type_map, $type_key);
181
}
182
183
public function isCustomType() {
184
return !strncmp($this->getType(), 'custom:', 7);
185
}
186
187
public function getCustomObject() {
188
if (!$this->customObject) {
189
if (!$this->isCustomType()) {
190
throw new Exception(pht('This option does not have a custom type!'));
191
}
192
$this->customObject = newv(substr($this->getType(), 7), array());
193
}
194
return $this->customObject;
195
}
196
197
public function getCustomData() {
198
return $this->customData;
199
}
200
201
public function setCustomData($data) {
202
$this->customData = $data;
203
return $this;
204
}
205
206
public function newDescriptionRemarkupView(PhabricatorUser $viewer) {
207
$description = $this->getDescription();
208
if (!strlen($description)) {
209
return null;
210
}
211
212
return new PHUIRemarkupView($viewer, $description);
213
}
214
215
}
216
217