[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/config/option/ -> PhabricatorConfigOption.php (source)

   1  <?php
   2  
   3  final class PhabricatorConfigOption
   4    extends Phobject
   5    implements PhabricatorMarkupInterface {
   6  
   7    private $key;
   8    private $default;
   9    private $summary;
  10    private $description;
  11    private $type;
  12    private $boolOptions;
  13    private $enumOptions;
  14    private $group;
  15    private $examples;
  16    private $locked;
  17    private $lockedMessage;
  18    private $hidden;
  19    private $masked;
  20    private $baseClass;
  21    private $customData;
  22    private $customObject;
  23  
  24    public function setBaseClass($base_class) {
  25      $this->baseClass = $base_class;
  26      return $this;
  27    }
  28  
  29    public function getBaseClass() {
  30      return $this->baseClass;
  31    }
  32  
  33    public function setMasked($masked) {
  34      $this->masked = $masked;
  35      return $this;
  36    }
  37  
  38    public function getMasked() {
  39      if ($this->masked) {
  40        return true;
  41      }
  42  
  43      if ($this->getHidden()) {
  44        return true;
  45      }
  46  
  47      return idx(
  48        PhabricatorEnv::getEnvConfig('config.mask'),
  49        $this->getKey(),
  50        false);
  51    }
  52  
  53    public function setHidden($hidden) {
  54      $this->hidden = $hidden;
  55      return $this;
  56    }
  57  
  58    public function getHidden() {
  59      if ($this->hidden) {
  60        return true;
  61      }
  62  
  63      return idx(
  64        PhabricatorEnv::getEnvConfig('config.hide'),
  65        $this->getKey(),
  66        false);
  67    }
  68  
  69    public function setLocked($locked) {
  70      $this->locked = $locked;
  71      return $this;
  72    }
  73  
  74    public function getLocked() {
  75      if ($this->locked) {
  76        return true;
  77      }
  78  
  79      if ($this->getHidden()) {
  80        return true;
  81      }
  82  
  83      return idx(
  84        PhabricatorEnv::getEnvConfig('config.lock'),
  85        $this->getKey(),
  86        false);
  87    }
  88  
  89    public function setLockedMessage($message) {
  90      $this->lockedMessage = $message;
  91      return $this;
  92    }
  93  
  94    public function getLockedMessage() {
  95      if ($this->lockedMessage !== null) {
  96        return $this->lockedMessage;
  97      }
  98      return pht(
  99        'This configuration is locked and can not be edited from the web '.
 100        'interface. Use `./bin/config` in `phabricator/` to edit it.');
 101    }
 102  
 103    public function addExample($value, $description) {
 104      $this->examples[] = array($value, $description);
 105      return $this;
 106    }
 107  
 108    public function getExamples() {
 109      return $this->examples;
 110    }
 111  
 112    public function setGroup(PhabricatorApplicationConfigOptions $group) {
 113      $this->group = $group;
 114      return $this;
 115    }
 116  
 117    public function getGroup() {
 118      return $this->group;
 119    }
 120  
 121    public function setBoolOptions(array $options) {
 122      $this->boolOptions = $options;
 123      return $this;
 124    }
 125  
 126    public function getBoolOptions() {
 127      if ($this->boolOptions) {
 128        return $this->boolOptions;
 129      }
 130      return array(
 131        pht('True'),
 132        pht('False'),
 133      );
 134    }
 135  
 136    public function setEnumOptions(array $options) {
 137      $this->enumOptions = $options;
 138      return $this;
 139    }
 140  
 141    public function getEnumOptions() {
 142      if ($this->enumOptions) {
 143        return $this->enumOptions;
 144      }
 145  
 146      throw new Exception(
 147        'Call setEnumOptions() before trying to access them!');
 148    }
 149  
 150    public function setKey($key) {
 151      $this->key = $key;
 152      return $this;
 153    }
 154  
 155    public function getKey() {
 156      return $this->key;
 157    }
 158  
 159    public function setDefault($default) {
 160      $this->default = $default;
 161      return $this;
 162    }
 163  
 164    public function getDefault() {
 165      return $this->default;
 166    }
 167  
 168    public function setSummary($summary) {
 169      $this->summary = $summary;
 170      return $this;
 171    }
 172  
 173    public function getSummary() {
 174      if (empty($this->summary)) {
 175        return $this->getDescription();
 176      }
 177      return $this->summary;
 178    }
 179  
 180    public function setDescription($description) {
 181      $this->description = $description;
 182      return $this;
 183    }
 184  
 185    public function getDescription() {
 186      return $this->description;
 187    }
 188  
 189    public function setType($type) {
 190      $this->type = $type;
 191      return $this;
 192    }
 193  
 194    public function getType() {
 195      return $this->type;
 196    }
 197  
 198    public function isCustomType() {
 199      return !strncmp($this->getType(), 'custom:', 7);
 200    }
 201  
 202    public function getCustomObject() {
 203      if (!$this->customObject) {
 204        if (!$this->isCustomType()) {
 205          throw new Exception('This option does not have a custom type!');
 206        }
 207        $this->customObject = newv(substr($this->getType(), 7), array());
 208      }
 209      return $this->customObject;
 210    }
 211  
 212    public function getCustomData() {
 213      return $this->customData;
 214    }
 215  
 216    public function setCustomData($data) {
 217      $this->customData = $data;
 218      return $this;
 219    }
 220  
 221  /* -(  PhabricatorMarkupInterface  )----------------------------------------- */
 222  
 223    public function getMarkupFieldKey($field) {
 224      return $this->getKey().':'.$field;
 225    }
 226  
 227    public function newMarkupEngine($field) {
 228      return PhabricatorMarkupEngine::newMarkupEngine(array());
 229    }
 230  
 231    public function getMarkupText($field) {
 232      switch ($field) {
 233        case 'description':
 234          $text = $this->getDescription();
 235          break;
 236        case 'summary':
 237          $text = $this->getSummary();
 238          break;
 239      }
 240  
 241      // TODO: We should probably implement this as a real Markup rule, but
 242      // markup rules are a bit of a mess right now and it doesn't hurt us to
 243      // fake this.
 244      $text = preg_replace(
 245        '/{{([^}]+)}}/',
 246        '[[/config/edit/\\1/ | \\1]]',
 247        $text);
 248  
 249      return $text;
 250    }
 251  
 252    public function didMarkupText($field, $output, PhutilMarkupEngine $engine) {
 253      return $output;
 254    }
 255  
 256    public function shouldUseMarkupCache($field) {
 257      return false;
 258    }
 259  
 260  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1