mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +01:00
Convert "bool" config values to new modular system
Summary: Ref T12845. Moves the "bool" values over. Test Plan: Set, deleted, and mangled bool values from CLI and web UI. Reviewers: chad, amckinley Reviewed By: amckinley Maniphest Tasks: T12845 Differential Revision: https://secure.phabricator.com/D18158
This commit is contained in:
parent
467be5e53f
commit
72119e786c
5 changed files with 64 additions and 49 deletions
|
@ -2153,6 +2153,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorBoardLayoutEngine' => 'applications/project/engine/PhabricatorBoardLayoutEngine.php',
|
||||
'PhabricatorBoardRenderingEngine' => 'applications/project/engine/PhabricatorBoardRenderingEngine.php',
|
||||
'PhabricatorBoardResponseEngine' => 'applications/project/engine/PhabricatorBoardResponseEngine.php',
|
||||
'PhabricatorBoolConfigType' => 'applications/config/type/PhabricatorBoolConfigType.php',
|
||||
'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php',
|
||||
'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php',
|
||||
'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php',
|
||||
|
@ -7356,6 +7357,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorBoardLayoutEngine' => 'Phobject',
|
||||
'PhabricatorBoardRenderingEngine' => 'Phobject',
|
||||
'PhabricatorBoardResponseEngine' => 'Phobject',
|
||||
'PhabricatorBoolConfigType' => 'PhabricatorTextConfigType',
|
||||
'PhabricatorBoolEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation',
|
||||
'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine',
|
||||
|
|
|
@ -350,20 +350,6 @@ final class PhabricatorConfigEditController
|
|||
case 'set':
|
||||
$set_value = array_fill_keys($request->getStrList('value'), true);
|
||||
break;
|
||||
case 'bool':
|
||||
switch ($value) {
|
||||
case 'true':
|
||||
$set_value = true;
|
||||
break;
|
||||
case 'false':
|
||||
$set_value = false;
|
||||
break;
|
||||
default:
|
||||
$e_value = pht('Invalid');
|
||||
$errors[] = pht('Value must be boolean, "true" or "false".');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'class':
|
||||
if (!class_exists($value)) {
|
||||
$e_value = pht('Invalid');
|
||||
|
@ -425,8 +411,6 @@ final class PhabricatorConfigEditController
|
|||
switch ($type) {
|
||||
case 'class':
|
||||
return $value;
|
||||
case 'bool':
|
||||
return $value ? 'true' : 'false';
|
||||
case 'set':
|
||||
return implode("\n", nonempty(array_keys($value), array()));
|
||||
default:
|
||||
|
@ -456,15 +440,6 @@ final class PhabricatorConfigEditController
|
|||
} else {
|
||||
$type = $option->getType();
|
||||
switch ($type) {
|
||||
case 'bool':
|
||||
$control = id(new AphrontFormSelectControl())
|
||||
->setOptions(
|
||||
array(
|
||||
'' => pht('(Use Default)'),
|
||||
'true' => idx($option->getBoolOptions(), 0),
|
||||
'false' => idx($option->getBoolOptions(), 1),
|
||||
));
|
||||
break;
|
||||
case 'class':
|
||||
$symbols = id(new PhutilSymbolLoader())
|
||||
->setType('class')
|
||||
|
|
|
@ -75,21 +75,6 @@ final class PhabricatorConfigManagementSetWorkflow
|
|||
case 'class':
|
||||
$value = (string)$value;
|
||||
break;
|
||||
case 'bool':
|
||||
if ($value == 'true') {
|
||||
$value = true;
|
||||
} else if ($value == 'false') {
|
||||
$value = false;
|
||||
} else {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
"Config key '%s' is of type '%s'. Specify '%s' or '%s'.",
|
||||
$key,
|
||||
$type,
|
||||
'true',
|
||||
'false'));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$value = json_decode($value, true);
|
||||
if (!is_array($value)) {
|
||||
|
|
|
@ -43,15 +43,6 @@ abstract class PhabricatorApplicationConfigOptions extends Phobject {
|
|||
}
|
||||
|
||||
switch ($option->getType()) {
|
||||
case 'bool':
|
||||
if ($value !== true &&
|
||||
$value !== false) {
|
||||
throw new PhabricatorConfigValidationException(
|
||||
pht(
|
||||
"Option '%s' is of type bool, but value is not true or false.",
|
||||
$option->getKey()));
|
||||
}
|
||||
break;
|
||||
case 'class':
|
||||
$symbols = id(new PhutilSymbolLoader())
|
||||
->setType('class')
|
||||
|
|
62
src/applications/config/type/PhabricatorBoolConfigType.php
Normal file
62
src/applications/config/type/PhabricatorBoolConfigType.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorBoolConfigType
|
||||
extends PhabricatorTextConfigType {
|
||||
|
||||
const TYPEKEY = 'bool';
|
||||
|
||||
protected function newCanonicalValue(
|
||||
PhabricatorConfigOption $option,
|
||||
$value) {
|
||||
|
||||
if (!preg_match('/^(true|false)\z/', $value)) {
|
||||
throw $this->newException(
|
||||
pht(
|
||||
'Value for option "%s" of type "%s" must be either '.
|
||||
'"true" or "false".',
|
||||
$option->getKey(),
|
||||
$this->getTypeKey()));
|
||||
}
|
||||
|
||||
return ($value === 'true');
|
||||
}
|
||||
|
||||
public function newDisplayValue(
|
||||
PhabricatorConfigOption $option,
|
||||
$value) {
|
||||
|
||||
if ($value) {
|
||||
return 'true';
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
|
||||
public function validateStoredValue(
|
||||
PhabricatorConfigOption $option,
|
||||
$value) {
|
||||
|
||||
if (!is_bool($value)) {
|
||||
throw $this->newException(
|
||||
pht(
|
||||
'Option "%s" is of type "%s", but the configured value is not '.
|
||||
'a boolean.',
|
||||
$option->getKey(),
|
||||
$this->getTypeKey()));
|
||||
}
|
||||
}
|
||||
|
||||
protected function newControl(PhabricatorConfigOption $option) {
|
||||
$bool_map = $option->getBoolOptions();
|
||||
|
||||
$map = array(
|
||||
'' => pht('(Use Default)'),
|
||||
) + array(
|
||||
'true' => idx($bool_map, 0),
|
||||
'false' => idx($bool_map, 1),
|
||||
);
|
||||
|
||||
return id(new AphrontFormSelectControl())
|
||||
->setOptions($map);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue