@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 "enum" and "string" config options to new modular option types

Summary: Ref T12845. This moves the "enum" and "string" types to the new code.

Test Plan: Set, deleted, and tried to set invalid values for various enum and string config values (header color, mail prefixes, etc) from the CLI and web.

Reviewers: chad, amckinley

Reviewed By: amckinley

Maniphest Tasks: T12845

Differential Revision: https://secure.phabricator.com/D18156

+89 -39
+4
src/__phutil_library_map__.php
··· 2755 2755 'PhabricatorEmojiRemarkupRule' => 'applications/macro/markup/PhabricatorEmojiRemarkupRule.php', 2756 2756 'PhabricatorEmojiTranslation' => 'infrastructure/internationalization/translation/PhabricatorEmojiTranslation.php', 2757 2757 'PhabricatorEmptyQueryException' => 'infrastructure/query/PhabricatorEmptyQueryException.php', 2758 + 'PhabricatorEnumConfigType' => 'applications/config/type/PhabricatorEnumConfigType.php', 2758 2759 'PhabricatorEnv' => 'infrastructure/env/PhabricatorEnv.php', 2759 2760 'PhabricatorEnvTestCase' => 'infrastructure/env/__tests__/PhabricatorEnvTestCase.php', 2760 2761 'PhabricatorEpochEditField' => 'applications/transactions/editfield/PhabricatorEpochEditField.php', ··· 4069 4070 'PhabricatorStoragePatch' => 'infrastructure/storage/management/PhabricatorStoragePatch.php', 4070 4071 'PhabricatorStorageSchemaSpec' => 'infrastructure/storage/schema/PhabricatorStorageSchemaSpec.php', 4071 4072 'PhabricatorStorageSetupCheck' => 'applications/config/check/PhabricatorStorageSetupCheck.php', 4073 + 'PhabricatorStringConfigType' => 'applications/config/type/PhabricatorStringConfigType.php', 4072 4074 'PhabricatorStringListEditField' => 'applications/transactions/editfield/PhabricatorStringListEditField.php', 4073 4075 'PhabricatorStringSetting' => 'applications/settings/setting/PhabricatorStringSetting.php', 4074 4076 'PhabricatorSubmitEditField' => 'applications/transactions/editfield/PhabricatorSubmitEditField.php', ··· 8044 8046 'PhabricatorEmojiRemarkupRule' => 'PhutilRemarkupRule', 8045 8047 'PhabricatorEmojiTranslation' => 'PhutilTranslation', 8046 8048 'PhabricatorEmptyQueryException' => 'Exception', 8049 + 'PhabricatorEnumConfigType' => 'PhabricatorTextConfigType', 8047 8050 'PhabricatorEnv' => 'Phobject', 8048 8051 'PhabricatorEnvTestCase' => 'PhabricatorTestCase', 8049 8052 'PhabricatorEpochEditField' => 'PhabricatorEditField', ··· 9605 9608 'PhabricatorStoragePatch' => 'Phobject', 9606 9609 'PhabricatorStorageSchemaSpec' => 'PhabricatorConfigSchemaSpec', 9607 9610 'PhabricatorStorageSetupCheck' => 'PhabricatorSetupCheck', 9611 + 'PhabricatorStringConfigType' => 'PhabricatorTextConfigType', 9608 9612 'PhabricatorStringListEditField' => 'PhabricatorEditField', 9609 9613 'PhabricatorStringSetting' => 'PhabricatorSetting', 9610 9614 'PhabricatorSubmitEditField' => 'PhabricatorEditField',
+1 -19
src/applications/config/controller/PhabricatorConfigEditController.php
··· 285 285 $canonical_value = $type->newValueFromRequestValue( 286 286 $option, 287 287 $value); 288 - $type->validateStoredValue($canonical_value); 288 + $type->validateStoredValue($option, $canonical_value); 289 289 $xaction = $type->newTransaction($option, $canonical_value); 290 290 } catch (PhabricatorConfigValidationException $ex) { 291 291 $errors[] = $ex->getMessage(); ··· 347 347 $set_value = null; 348 348 349 349 switch ($type) { 350 - case 'string': 351 - case 'enum': 352 - $set_value = (string)$value; 353 - break; 354 350 case 'list<string>': 355 351 case 'list<regex>': 356 352 $set_value = phutil_split_lines( ··· 441 437 } else { 442 438 $type = $option->getType(); 443 439 switch ($type) { 444 - case 'string': 445 - case 'enum': 446 440 case 'class': 447 441 return $value; 448 442 case 'bool': ··· 479 473 } else { 480 474 $type = $option->getType(); 481 475 switch ($type) { 482 - case 'string': 483 - $control = id(new AphrontFormTextControl()); 484 - break; 485 476 case 'bool': 486 477 $control = id(new AphrontFormSelectControl()) 487 478 ->setOptions( ··· 490 481 'true' => idx($option->getBoolOptions(), 0), 491 482 'false' => idx($option->getBoolOptions(), 1), 492 483 )); 493 - break; 494 - case 'enum': 495 - $options = array_mergev( 496 - array( 497 - array('' => pht('(Use Default)')), 498 - $option->getEnumOptions(), 499 - )); 500 - $control = id(new AphrontFormSelectControl()) 501 - ->setOptions($options); 502 484 break; 503 485 case 'class': 504 486 $symbols = id(new PhutilSymbolLoader())
-2
src/applications/config/management/PhabricatorConfigManagementSetWorkflow.php
··· 71 71 } else { 72 72 $type = $option->getType(); 73 73 switch ($type) { 74 - case 'string': 75 74 case 'class': 76 - case 'enum': 77 75 $value = (string)$value; 78 76 break; 79 77 case 'bool':
-8
src/applications/config/option/PhabricatorApplicationConfigOptions.php
··· 52 52 $option->getKey())); 53 53 } 54 54 break; 55 - case 'string': 56 - if (!is_string($value)) { 57 - throw new PhabricatorConfigValidationException( 58 - pht( 59 - "Option '%s' is of type string, but value is not a string.", 60 - $option->getKey())); 61 - } 62 - break; 63 55 case 'class': 64 56 $symbols = id(new PhutilSymbolLoader()) 65 57 ->setType('class')
+3 -3
src/applications/config/option/PhabricatorMetaMTAConfigOptions.php
··· 297 297 $this->newOption('metamta.user-address-format', 'enum', 'full') 298 298 ->setEnumOptions( 299 299 array( 300 - 'short' => 'short', 301 - 'real' => 'real', 302 - 'full' => 'full', 300 + 'short' => pht('Short'), 301 + 'real' => pht('Real'), 302 + 'full' => pht('Full'), 303 303 )) 304 304 ->setSummary(pht('Control how Phabricator renders user names in mail.')) 305 305 ->setDescription($address_description)
+6 -6
src/applications/config/option/PhabricatorUIConfigOptions.php
··· 21 21 22 22 public function getOptions() { 23 23 $options = array( 24 - 'blindigo' => 'blindigo', 25 - 'red' => 'red', 26 - 'blue' => 'blue', 27 - 'green' => 'green', 28 - 'indigo' => 'indigo', 29 - 'dark' => 'dark', 24 + 'blindigo' => pht('Blindigo'), 25 + 'red' => pht('Red'), 26 + 'blue' => pht('Blue'), 27 + 'green' => pht('Green'), 28 + 'indigo' => pht('Indigo'), 29 + 'dark' => pht('Dark'), 30 30 ); 31 31 32 32 $example = <<<EOJSON
+43
src/applications/config/type/PhabricatorEnumConfigType.php
··· 1 + <?php 2 + 3 + final class PhabricatorEnumConfigType 4 + extends PhabricatorTextConfigType { 5 + 6 + const TYPEKEY = 'enum'; 7 + 8 + public function validateStoredValue( 9 + PhabricatorConfigOption $option, 10 + $value) { 11 + 12 + if (!is_string($value)) { 13 + throw $this->newException( 14 + pht( 15 + 'Option "%s" is of type "%s", but the configured value is not '. 16 + 'a string.', 17 + $option->getKey(), 18 + $this->getTypeKey())); 19 + } 20 + 21 + $map = $option->getEnumOptions(); 22 + if (!isset($map[$value])) { 23 + throw $this->newException( 24 + pht( 25 + 'Option "%s" is of type "%s", but the current value ("%s") is not '. 26 + 'among the set of valid values: %s.', 27 + $option->getKey(), 28 + $this->getTypeKey(), 29 + $value, 30 + implode(', ', array_keys($map)))); 31 + } 32 + } 33 + 34 + protected function newControl(PhabricatorConfigOption $option) { 35 + $map = array( 36 + '' => pht('(Use Default)'), 37 + ) + $option->getEnumOptions(); 38 + 39 + return id(new AphrontFormSelectControl()) 40 + ->setOptions($map); 41 + } 42 + 43 + }
+22
src/applications/config/type/PhabricatorStringConfigType.php
··· 1 + <?php 2 + 3 + final class PhabricatorStringConfigType 4 + extends PhabricatorTextConfigType { 5 + 6 + const TYPEKEY = 'string'; 7 + 8 + public function validateStoredValue( 9 + PhabricatorConfigOption $option, 10 + $value) { 11 + 12 + if (!is_string($value)) { 13 + throw $this->newException( 14 + pht( 15 + 'Option "%s" is of type "%s", but the configured value is not '. 16 + 'a string.', 17 + $option->getKey(), 18 + $this->getTypeKey())); 19 + } 20 + } 21 + 22 + }
+6
src/applications/config/type/PhabricatorTextConfigType.php
··· 10 10 return (bool)strlen($value); 11 11 } 12 12 13 + protected function newCanonicalValue( 14 + PhabricatorConfigOption $option, 15 + $value) { 16 + return (string)$value; 17 + } 18 + 13 19 protected function newHTTPParameterType() { 14 20 return new AphrontStringHTTPParameterType(); 15 21 }
+4 -1
src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
··· 260 260 ->setDescription( 261 261 pht('Format for inlined or attached patches.')) 262 262 ->setEnumOptions( 263 - array('unified' => 'unified', 'git' => 'git')), 263 + array( 264 + 'unified' => pht('Unified'), 265 + 'git' => pht('Git'), 266 + )), 264 267 ); 265 268 } 266 269