2012-12-31 00:36:06 +01:00
|
|
|
<?php
|
|
|
|
|
2013-01-01 23:09:17 +01:00
|
|
|
final class PhabricatorConfigOption
|
|
|
|
extends Phobject
|
2013-01-22 22:57:02 +01:00
|
|
|
implements PhabricatorMarkupInterface {
|
2012-12-31 00:36:06 +01:00
|
|
|
|
|
|
|
private $key;
|
|
|
|
private $default;
|
|
|
|
private $summary;
|
|
|
|
private $description;
|
|
|
|
private $type;
|
2013-01-09 17:14:26 +01:00
|
|
|
private $boolOptions;
|
2013-01-22 03:46:21 +01:00
|
|
|
private $enumOptions;
|
2012-12-31 00:36:06 +01:00
|
|
|
private $group;
|
2013-01-01 23:09:17 +01:00
|
|
|
private $examples;
|
2013-01-02 23:02:43 +01:00
|
|
|
private $locked;
|
2013-01-03 15:01:14 +01:00
|
|
|
private $hidden;
|
|
|
|
private $masked;
|
|
|
|
private $baseClass;
|
2013-06-07 21:36:18 +02:00
|
|
|
private $customData;
|
|
|
|
private $customObject;
|
2013-01-03 15:01:14 +01:00
|
|
|
|
|
|
|
public function setBaseClass($base_class) {
|
|
|
|
$this->baseClass = $base_class;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBaseClass() {
|
|
|
|
return $this->baseClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMasked($masked) {
|
|
|
|
$this->masked = $masked;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMasked() {
|
2013-01-16 19:52:09 +01:00
|
|
|
if ($this->masked) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-03 15:01:14 +01:00
|
|
|
if ($this->getHidden()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-16 19:52:09 +01:00
|
|
|
|
|
|
|
return idx(
|
2013-01-19 21:11:11 +01:00
|
|
|
PhabricatorEnv::getEnvConfig('config.mask'),
|
2013-01-16 19:52:09 +01:00
|
|
|
$this->getKey(),
|
|
|
|
false);
|
2013-01-03 15:01:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setHidden($hidden) {
|
|
|
|
$this->hidden = $hidden;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHidden() {
|
2013-01-16 19:52:09 +01:00
|
|
|
if ($this->hidden) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return idx(
|
2013-01-19 21:11:11 +01:00
|
|
|
PhabricatorEnv::getEnvConfig('config.hide'),
|
2013-01-16 19:52:09 +01:00
|
|
|
$this->getKey(),
|
|
|
|
false);
|
2013-01-03 15:01:14 +01:00
|
|
|
}
|
2013-01-02 23:02:43 +01:00
|
|
|
|
|
|
|
public function setLocked($locked) {
|
|
|
|
$this->locked = $locked;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLocked() {
|
2013-01-16 19:52:09 +01:00
|
|
|
if ($this->locked) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-03 15:01:14 +01:00
|
|
|
if ($this->getHidden()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-16 19:52:09 +01:00
|
|
|
|
|
|
|
return idx(
|
2013-01-19 21:11:11 +01:00
|
|
|
PhabricatorEnv::getEnvConfig('config.lock'),
|
2013-01-16 19:52:09 +01:00
|
|
|
$this->getKey(),
|
|
|
|
false);
|
2013-01-02 23:02:43 +01:00
|
|
|
}
|
2012-12-31 00:36:06 +01:00
|
|
|
|
2013-01-01 23:09:17 +01:00
|
|
|
public function addExample($value, $description) {
|
|
|
|
$this->examples[] = array($value, $description);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExamples() {
|
|
|
|
return $this->examples;
|
|
|
|
}
|
2012-12-31 00:36:06 +01:00
|
|
|
|
|
|
|
public function setGroup(PhabricatorApplicationConfigOptions $group) {
|
|
|
|
$this->group = $group;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGroup() {
|
|
|
|
return $this->group;
|
|
|
|
}
|
|
|
|
|
2013-01-09 17:14:26 +01:00
|
|
|
public function setBoolOptions(array $options) {
|
|
|
|
$this->boolOptions = $options;
|
2012-12-31 00:36:06 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-01-09 17:14:26 +01:00
|
|
|
public function getBoolOptions() {
|
|
|
|
if ($this->boolOptions) {
|
|
|
|
return $this->boolOptions;
|
|
|
|
}
|
|
|
|
return array(
|
|
|
|
pht('True'),
|
|
|
|
pht('False'),
|
|
|
|
);
|
2012-12-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 03:46:21 +01:00
|
|
|
public function setEnumOptions(array $options) {
|
|
|
|
$this->enumOptions = $options;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEnumOptions() {
|
|
|
|
if ($this->enumOptions) {
|
|
|
|
return $this->enumOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Exception(
|
|
|
|
'Call setEnumOptions() before trying to access them!');
|
|
|
|
}
|
|
|
|
|
2012-12-31 00:36:06 +01:00
|
|
|
public function setKey($key) {
|
|
|
|
$this->key = $key;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getKey() {
|
|
|
|
return $this->key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDefault($default) {
|
|
|
|
$this->default = $default;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDefault() {
|
|
|
|
return $this->default;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSummary($summary) {
|
|
|
|
$this->summary = $summary;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummary() {
|
2013-01-01 23:09:29 +01:00
|
|
|
if (empty($this->summary)) {
|
|
|
|
return $this->getDescription();
|
|
|
|
}
|
2012-12-31 00:36:06 +01:00
|
|
|
return $this->summary;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDescription($description) {
|
|
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription() {
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setType($type) {
|
|
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getType() {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
2013-06-07 21:36:18 +02:00
|
|
|
public function isCustomType() {
|
|
|
|
return !strncmp($this->getType(), 'custom:', 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCustomObject() {
|
|
|
|
if (!$this->customObject) {
|
|
|
|
if (!$this->isCustomType()) {
|
|
|
|
throw new Exception("This option does not have a custom type!");
|
|
|
|
}
|
|
|
|
$this->customObject = newv(substr($this->getType(), 7), array());
|
|
|
|
}
|
|
|
|
return $this->customObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCustomData() {
|
|
|
|
return $this->customData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCustomData($data) {
|
|
|
|
$this->customData = $data;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-01-01 23:09:17 +01:00
|
|
|
/* -( PhabricatorMarkupInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
public function getMarkupFieldKey($field) {
|
|
|
|
return $this->getKey().':'.$field;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newMarkupEngine($field) {
|
|
|
|
return PhabricatorMarkupEngine::newMarkupEngine(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMarkupText($field) {
|
2013-01-16 18:08:13 +01:00
|
|
|
switch ($field) {
|
|
|
|
case 'description':
|
|
|
|
$text = $this->getDescription();
|
|
|
|
break;
|
|
|
|
case 'summary':
|
|
|
|
$text = $this->getSummary();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: We should probably implement this as a real Markup rule, but
|
|
|
|
// markup rules are a bit of a mess right now and it doesn't hurt us to
|
|
|
|
// fake this.
|
|
|
|
$text = preg_replace(
|
|
|
|
'/{{([^}]+)}}/',
|
|
|
|
'[[/config/edit/\\1/ | \\1]]',
|
|
|
|
$text);
|
|
|
|
|
|
|
|
return $text;
|
2013-01-01 23:09:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function didMarkupText($field, $output, PhutilMarkupEngine $engine) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldUseMarkupCache($field) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-31 00:36:06 +01:00
|
|
|
}
|