1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +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:
epriestley 2017-06-26 09:40:37 -07:00
parent 467be5e53f
commit 72119e786c
5 changed files with 64 additions and 49 deletions

View file

@ -2153,6 +2153,7 @@ phutil_register_library_map(array(
'PhabricatorBoardLayoutEngine' => 'applications/project/engine/PhabricatorBoardLayoutEngine.php', 'PhabricatorBoardLayoutEngine' => 'applications/project/engine/PhabricatorBoardLayoutEngine.php',
'PhabricatorBoardRenderingEngine' => 'applications/project/engine/PhabricatorBoardRenderingEngine.php', 'PhabricatorBoardRenderingEngine' => 'applications/project/engine/PhabricatorBoardRenderingEngine.php',
'PhabricatorBoardResponseEngine' => 'applications/project/engine/PhabricatorBoardResponseEngine.php', 'PhabricatorBoardResponseEngine' => 'applications/project/engine/PhabricatorBoardResponseEngine.php',
'PhabricatorBoolConfigType' => 'applications/config/type/PhabricatorBoolConfigType.php',
'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php', 'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php',
'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php', 'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php',
'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php', 'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php',
@ -7356,6 +7357,7 @@ phutil_register_library_map(array(
'PhabricatorBoardLayoutEngine' => 'Phobject', 'PhabricatorBoardLayoutEngine' => 'Phobject',
'PhabricatorBoardRenderingEngine' => 'Phobject', 'PhabricatorBoardRenderingEngine' => 'Phobject',
'PhabricatorBoardResponseEngine' => 'Phobject', 'PhabricatorBoardResponseEngine' => 'Phobject',
'PhabricatorBoolConfigType' => 'PhabricatorTextConfigType',
'PhabricatorBoolEditField' => 'PhabricatorEditField', 'PhabricatorBoolEditField' => 'PhabricatorEditField',
'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation', 'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation',
'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine', 'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine',

View file

@ -350,20 +350,6 @@ final class PhabricatorConfigEditController
case 'set': case 'set':
$set_value = array_fill_keys($request->getStrList('value'), true); $set_value = array_fill_keys($request->getStrList('value'), true);
break; 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': case 'class':
if (!class_exists($value)) { if (!class_exists($value)) {
$e_value = pht('Invalid'); $e_value = pht('Invalid');
@ -425,8 +411,6 @@ final class PhabricatorConfigEditController
switch ($type) { switch ($type) {
case 'class': case 'class':
return $value; return $value;
case 'bool':
return $value ? 'true' : 'false';
case 'set': case 'set':
return implode("\n", nonempty(array_keys($value), array())); return implode("\n", nonempty(array_keys($value), array()));
default: default:
@ -456,15 +440,6 @@ final class PhabricatorConfigEditController
} else { } else {
$type = $option->getType(); $type = $option->getType();
switch ($type) { 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': case 'class':
$symbols = id(new PhutilSymbolLoader()) $symbols = id(new PhutilSymbolLoader())
->setType('class') ->setType('class')

View file

@ -75,21 +75,6 @@ final class PhabricatorConfigManagementSetWorkflow
case 'class': case 'class':
$value = (string)$value; $value = (string)$value;
break; 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: default:
$value = json_decode($value, true); $value = json_decode($value, true);
if (!is_array($value)) { if (!is_array($value)) {

View file

@ -43,15 +43,6 @@ abstract class PhabricatorApplicationConfigOptions extends Phobject {
} }
switch ($option->getType()) { 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': case 'class':
$symbols = id(new PhutilSymbolLoader()) $symbols = id(new PhutilSymbolLoader())
->setType('class') ->setType('class')

View 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);
}
}