Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14084113
D18158.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D18158.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2153,6 +2153,7 @@
'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 @@
'PhabricatorBoardLayoutEngine' => 'Phobject',
'PhabricatorBoardRenderingEngine' => 'Phobject',
'PhabricatorBoardResponseEngine' => 'Phobject',
+ 'PhabricatorBoolConfigType' => 'PhabricatorTextConfigType',
'PhabricatorBoolEditField' => 'PhabricatorEditField',
'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation',
'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine',
diff --git a/src/applications/config/controller/PhabricatorConfigEditController.php b/src/applications/config/controller/PhabricatorConfigEditController.php
--- a/src/applications/config/controller/PhabricatorConfigEditController.php
+++ b/src/applications/config/controller/PhabricatorConfigEditController.php
@@ -350,20 +350,6 @@
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 @@
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 @@
} 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')
diff --git a/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php b/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
--- a/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
+++ b/src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
@@ -75,21 +75,6 @@
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)) {
diff --git a/src/applications/config/option/PhabricatorApplicationConfigOptions.php b/src/applications/config/option/PhabricatorApplicationConfigOptions.php
--- a/src/applications/config/option/PhabricatorApplicationConfigOptions.php
+++ b/src/applications/config/option/PhabricatorApplicationConfigOptions.php
@@ -43,15 +43,6 @@
}
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')
diff --git a/src/applications/config/type/PhabricatorBoolConfigType.php b/src/applications/config/type/PhabricatorBoolConfigType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/config/type/PhabricatorBoolConfigType.php
@@ -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);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 6:51 AM (19 h, 44 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6776616
Default Alt Text
D18158.diff (6 KB)
Attached To
Mode
D18158: Convert "bool" config values to new modular system
Attached
Detach File
Event Timeline
Log In to Comment