@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+64 -49
+2
src/__phutil_library_map__.php
··· 2153 2153 'PhabricatorBoardLayoutEngine' => 'applications/project/engine/PhabricatorBoardLayoutEngine.php', 2154 2154 'PhabricatorBoardRenderingEngine' => 'applications/project/engine/PhabricatorBoardRenderingEngine.php', 2155 2155 'PhabricatorBoardResponseEngine' => 'applications/project/engine/PhabricatorBoardResponseEngine.php', 2156 + 'PhabricatorBoolConfigType' => 'applications/config/type/PhabricatorBoolConfigType.php', 2156 2157 'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php', 2157 2158 'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php', 2158 2159 'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php', ··· 7356 7357 'PhabricatorBoardLayoutEngine' => 'Phobject', 7357 7358 'PhabricatorBoardRenderingEngine' => 'Phobject', 7358 7359 'PhabricatorBoardResponseEngine' => 'Phobject', 7360 + 'PhabricatorBoolConfigType' => 'PhabricatorTextConfigType', 7359 7361 'PhabricatorBoolEditField' => 'PhabricatorEditField', 7360 7362 'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation', 7361 7363 'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine',
-25
src/applications/config/controller/PhabricatorConfigEditController.php
··· 350 350 case 'set': 351 351 $set_value = array_fill_keys($request->getStrList('value'), true); 352 352 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; 367 353 case 'class': 368 354 if (!class_exists($value)) { 369 355 $e_value = pht('Invalid'); ··· 425 411 switch ($type) { 426 412 case 'class': 427 413 return $value; 428 - case 'bool': 429 - return $value ? 'true' : 'false'; 430 414 case 'set': 431 415 return implode("\n", nonempty(array_keys($value), array())); 432 416 default: ··· 456 440 } else { 457 441 $type = $option->getType(); 458 442 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; 468 443 case 'class': 469 444 $symbols = id(new PhutilSymbolLoader()) 470 445 ->setType('class')
-15
src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
··· 75 75 case 'class': 76 76 $value = (string)$value; 77 77 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; 93 78 default: 94 79 $value = json_decode($value, true); 95 80 if (!is_array($value)) {
-9
src/applications/config/option/PhabricatorApplicationConfigOptions.php
··· 43 43 } 44 44 45 45 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; 55 46 case 'class': 56 47 $symbols = id(new PhutilSymbolLoader()) 57 48 ->setType('class')
+62
src/applications/config/type/PhabricatorBoolConfigType.php
··· 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 + }