Skip to content

Commit 72119e7

Browse files
author
epriestley
committedJun 27, 2017
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
1 parent 467be5e commit 72119e7

5 files changed

+64
-49
lines changed
 

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,7 @@
21532153
'PhabricatorBoardLayoutEngine' => 'applications/project/engine/PhabricatorBoardLayoutEngine.php',
21542154
'PhabricatorBoardRenderingEngine' => 'applications/project/engine/PhabricatorBoardRenderingEngine.php',
21552155
'PhabricatorBoardResponseEngine' => 'applications/project/engine/PhabricatorBoardResponseEngine.php',
2156+
'PhabricatorBoolConfigType' => 'applications/config/type/PhabricatorBoolConfigType.php',
21562157
'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php',
21572158
'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php',
21582159
'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php',
@@ -7356,6 +7357,7 @@
73567357
'PhabricatorBoardLayoutEngine' => 'Phobject',
73577358
'PhabricatorBoardRenderingEngine' => 'Phobject',
73587359
'PhabricatorBoardResponseEngine' => 'Phobject',
7360+
'PhabricatorBoolConfigType' => 'PhabricatorTextConfigType',
73597361
'PhabricatorBoolEditField' => 'PhabricatorEditField',
73607362
'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation',
73617363
'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine',

‎src/applications/config/controller/PhabricatorConfigEditController.php

-25
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,6 @@ private function readRequest(
350350
case 'set':
351351
$set_value = array_fill_keys($request->getStrList('value'), true);
352352
break;
353-
case 'bool':
354-
switch ($value) {
355-
case 'true':
356-
$set_value = true;
357-
break;
358-
case 'false':
359-
$set_value = false;
360-
break;
361-
default:
362-
$e_value = pht('Invalid');
363-
$errors[] = pht('Value must be boolean, "true" or "false".');
364-
break;
365-
}
366-
break;
367353
case 'class':
368354
if (!class_exists($value)) {
369355
$e_value = pht('Invalid');
@@ -425,8 +411,6 @@ private function getDisplayValue(
425411
switch ($type) {
426412
case 'class':
427413
return $value;
428-
case 'bool':
429-
return $value ? 'true' : 'false';
430414
case 'set':
431415
return implode("\n", nonempty(array_keys($value), array()));
432416
default:
@@ -456,15 +440,6 @@ private function renderControls(
456440
} else {
457441
$type = $option->getType();
458442
switch ($type) {
459-
case 'bool':
460-
$control = id(new AphrontFormSelectControl())
461-
->setOptions(
462-
array(
463-
'' => pht('(Use Default)'),
464-
'true' => idx($option->getBoolOptions(), 0),
465-
'false' => idx($option->getBoolOptions(), 1),
466-
));
467-
break;
468443
case 'class':
469444
$symbols = id(new PhutilSymbolLoader())
470445
->setType('class')

‎src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php

-15
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,6 @@ public function execute(PhutilArgumentParser $args) {
7575
case 'class':
7676
$value = (string)$value;
7777
break;
78-
case 'bool':
79-
if ($value == 'true') {
80-
$value = true;
81-
} else if ($value == 'false') {
82-
$value = false;
83-
} else {
84-
throw new PhutilArgumentUsageException(
85-
pht(
86-
"Config key '%s' is of type '%s'. Specify '%s' or '%s'.",
87-
$key,
88-
$type,
89-
'true',
90-
'false'));
91-
}
92-
break;
9378
default:
9479
$value = json_decode($value, true);
9580
if (!is_array($value)) {

‎src/applications/config/option/PhabricatorApplicationConfigOptions.php

-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ public function validateOption(PhabricatorConfigOption $option, $value) {
4343
}
4444

4545
switch ($option->getType()) {
46-
case 'bool':
47-
if ($value !== true &&
48-
$value !== false) {
49-
throw new PhabricatorConfigValidationException(
50-
pht(
51-
"Option '%s' is of type bool, but value is not true or false.",
52-
$option->getKey()));
53-
}
54-
break;
5546
case 'class':
5647
$symbols = id(new PhutilSymbolLoader())
5748
->setType('class')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
final class PhabricatorBoolConfigType
4+
extends PhabricatorTextConfigType {
5+
6+
const TYPEKEY = 'bool';
7+
8+
protected function newCanonicalValue(
9+
PhabricatorConfigOption $option,
10+
$value) {
11+
12+
if (!preg_match('/^(true|false)\z/', $value)) {
13+
throw $this->newException(
14+
pht(
15+
'Value for option "%s" of type "%s" must be either '.
16+
'"true" or "false".',
17+
$option->getKey(),
18+
$this->getTypeKey()));
19+
}
20+
21+
return ($value === 'true');
22+
}
23+
24+
public function newDisplayValue(
25+
PhabricatorConfigOption $option,
26+
$value) {
27+
28+
if ($value) {
29+
return 'true';
30+
} else {
31+
return 'false';
32+
}
33+
}
34+
35+
public function validateStoredValue(
36+
PhabricatorConfigOption $option,
37+
$value) {
38+
39+
if (!is_bool($value)) {
40+
throw $this->newException(
41+
pht(
42+
'Option "%s" is of type "%s", but the configured value is not '.
43+
'a boolean.',
44+
$option->getKey(),
45+
$this->getTypeKey()));
46+
}
47+
}
48+
49+
protected function newControl(PhabricatorConfigOption $option) {
50+
$bool_map = $option->getBoolOptions();
51+
52+
$map = array(
53+
'' => pht('(Use Default)'),
54+
) + array(
55+
'true' => idx($bool_map, 0),
56+
'false' => idx($bool_map, 1),
57+
);
58+
59+
return id(new AphrontFormSelectControl())
60+
->setOptions($map);
61+
}
62+
}

0 commit comments

Comments
 (0)
Failed to load comments.