Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15386037
D18156.id43682.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D18156.id43682.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
@@ -2755,6 +2755,7 @@
'PhabricatorEmojiRemarkupRule' => 'applications/macro/markup/PhabricatorEmojiRemarkupRule.php',
'PhabricatorEmojiTranslation' => 'infrastructure/internationalization/translation/PhabricatorEmojiTranslation.php',
'PhabricatorEmptyQueryException' => 'infrastructure/query/PhabricatorEmptyQueryException.php',
+ 'PhabricatorEnumConfigType' => 'applications/config/type/PhabricatorEnumConfigType.php',
'PhabricatorEnv' => 'infrastructure/env/PhabricatorEnv.php',
'PhabricatorEnvTestCase' => 'infrastructure/env/__tests__/PhabricatorEnvTestCase.php',
'PhabricatorEpochEditField' => 'applications/transactions/editfield/PhabricatorEpochEditField.php',
@@ -4069,6 +4070,7 @@
'PhabricatorStoragePatch' => 'infrastructure/storage/management/PhabricatorStoragePatch.php',
'PhabricatorStorageSchemaSpec' => 'infrastructure/storage/schema/PhabricatorStorageSchemaSpec.php',
'PhabricatorStorageSetupCheck' => 'applications/config/check/PhabricatorStorageSetupCheck.php',
+ 'PhabricatorStringConfigType' => 'applications/config/type/PhabricatorStringConfigType.php',
'PhabricatorStringListEditField' => 'applications/transactions/editfield/PhabricatorStringListEditField.php',
'PhabricatorStringSetting' => 'applications/settings/setting/PhabricatorStringSetting.php',
'PhabricatorSubmitEditField' => 'applications/transactions/editfield/PhabricatorSubmitEditField.php',
@@ -8044,6 +8046,7 @@
'PhabricatorEmojiRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorEmojiTranslation' => 'PhutilTranslation',
'PhabricatorEmptyQueryException' => 'Exception',
+ 'PhabricatorEnumConfigType' => 'PhabricatorTextConfigType',
'PhabricatorEnv' => 'Phobject',
'PhabricatorEnvTestCase' => 'PhabricatorTestCase',
'PhabricatorEpochEditField' => 'PhabricatorEditField',
@@ -9605,6 +9608,7 @@
'PhabricatorStoragePatch' => 'Phobject',
'PhabricatorStorageSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhabricatorStorageSetupCheck' => 'PhabricatorSetupCheck',
+ 'PhabricatorStringConfigType' => 'PhabricatorTextConfigType',
'PhabricatorStringListEditField' => 'PhabricatorEditField',
'PhabricatorStringSetting' => 'PhabricatorSetting',
'PhabricatorSubmitEditField' => 'PhabricatorEditField',
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
@@ -285,7 +285,7 @@
$canonical_value = $type->newValueFromRequestValue(
$option,
$value);
- $type->validateStoredValue($canonical_value);
+ $type->validateStoredValue($option, $canonical_value);
$xaction = $type->newTransaction($option, $canonical_value);
} catch (PhabricatorConfigValidationException $ex) {
$errors[] = $ex->getMessage();
@@ -347,10 +347,6 @@
$set_value = null;
switch ($type) {
- case 'string':
- case 'enum':
- $set_value = (string)$value;
- break;
case 'list<string>':
case 'list<regex>':
$set_value = phutil_split_lines(
@@ -441,8 +437,6 @@
} else {
$type = $option->getType();
switch ($type) {
- case 'string':
- case 'enum':
case 'class':
return $value;
case 'bool':
@@ -479,9 +473,6 @@
} else {
$type = $option->getType();
switch ($type) {
- case 'string':
- $control = id(new AphrontFormTextControl());
- break;
case 'bool':
$control = id(new AphrontFormSelectControl())
->setOptions(
@@ -491,15 +482,6 @@
'false' => idx($option->getBoolOptions(), 1),
));
break;
- case 'enum':
- $options = array_mergev(
- array(
- array('' => pht('(Use Default)')),
- $option->getEnumOptions(),
- ));
- $control = id(new AphrontFormSelectControl())
- ->setOptions($options);
- 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
@@ -71,9 +71,7 @@
} else {
$type = $option->getType();
switch ($type) {
- case 'string':
case 'class':
- case 'enum':
$value = (string)$value;
break;
case 'bool':
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
@@ -52,14 +52,6 @@
$option->getKey()));
}
break;
- case 'string':
- if (!is_string($value)) {
- throw new PhabricatorConfigValidationException(
- pht(
- "Option '%s' is of type string, but value is not a string.",
- $option->getKey()));
- }
- break;
case 'class':
$symbols = id(new PhutilSymbolLoader())
->setType('class')
diff --git a/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php b/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php
--- a/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php
+++ b/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php
@@ -297,9 +297,9 @@
$this->newOption('metamta.user-address-format', 'enum', 'full')
->setEnumOptions(
array(
- 'short' => 'short',
- 'real' => 'real',
- 'full' => 'full',
+ 'short' => pht('Short'),
+ 'real' => pht('Real'),
+ 'full' => pht('Full'),
))
->setSummary(pht('Control how Phabricator renders user names in mail.'))
->setDescription($address_description)
diff --git a/src/applications/config/option/PhabricatorUIConfigOptions.php b/src/applications/config/option/PhabricatorUIConfigOptions.php
--- a/src/applications/config/option/PhabricatorUIConfigOptions.php
+++ b/src/applications/config/option/PhabricatorUIConfigOptions.php
@@ -21,12 +21,12 @@
public function getOptions() {
$options = array(
- 'blindigo' => 'blindigo',
- 'red' => 'red',
- 'blue' => 'blue',
- 'green' => 'green',
- 'indigo' => 'indigo',
- 'dark' => 'dark',
+ 'blindigo' => pht('Blindigo'),
+ 'red' => pht('Red'),
+ 'blue' => pht('Blue'),
+ 'green' => pht('Green'),
+ 'indigo' => pht('Indigo'),
+ 'dark' => pht('Dark'),
);
$example = <<<EOJSON
diff --git a/src/applications/config/type/PhabricatorEnumConfigType.php b/src/applications/config/type/PhabricatorEnumConfigType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/config/type/PhabricatorEnumConfigType.php
@@ -0,0 +1,43 @@
+<?php
+
+final class PhabricatorEnumConfigType
+ extends PhabricatorTextConfigType {
+
+ const TYPEKEY = 'enum';
+
+ public function validateStoredValue(
+ PhabricatorConfigOption $option,
+ $value) {
+
+ if (!is_string($value)) {
+ throw $this->newException(
+ pht(
+ 'Option "%s" is of type "%s", but the configured value is not '.
+ 'a string.',
+ $option->getKey(),
+ $this->getTypeKey()));
+ }
+
+ $map = $option->getEnumOptions();
+ if (!isset($map[$value])) {
+ throw $this->newException(
+ pht(
+ 'Option "%s" is of type "%s", but the current value ("%s") is not '.
+ 'among the set of valid values: %s.',
+ $option->getKey(),
+ $this->getTypeKey(),
+ $value,
+ implode(', ', array_keys($map))));
+ }
+ }
+
+ protected function newControl(PhabricatorConfigOption $option) {
+ $map = array(
+ '' => pht('(Use Default)'),
+ ) + $option->getEnumOptions();
+
+ return id(new AphrontFormSelectControl())
+ ->setOptions($map);
+ }
+
+}
diff --git a/src/applications/config/type/PhabricatorStringConfigType.php b/src/applications/config/type/PhabricatorStringConfigType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/config/type/PhabricatorStringConfigType.php
@@ -0,0 +1,22 @@
+<?php
+
+final class PhabricatorStringConfigType
+ extends PhabricatorTextConfigType {
+
+ const TYPEKEY = 'string';
+
+ public function validateStoredValue(
+ PhabricatorConfigOption $option,
+ $value) {
+
+ if (!is_string($value)) {
+ throw $this->newException(
+ pht(
+ 'Option "%s" is of type "%s", but the configured value is not '.
+ 'a string.',
+ $option->getKey(),
+ $this->getTypeKey()));
+ }
+ }
+
+}
diff --git a/src/applications/config/type/PhabricatorTextConfigType.php b/src/applications/config/type/PhabricatorTextConfigType.php
--- a/src/applications/config/type/PhabricatorTextConfigType.php
+++ b/src/applications/config/type/PhabricatorTextConfigType.php
@@ -10,6 +10,12 @@
return (bool)strlen($value);
}
+ protected function newCanonicalValue(
+ PhabricatorConfigOption $option,
+ $value) {
+ return (string)$value;
+ }
+
protected function newHTTPParameterType() {
return new AphrontStringHTTPParameterType();
}
diff --git a/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php b/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
--- a/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
+++ b/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
@@ -260,7 +260,10 @@
->setDescription(
pht('Format for inlined or attached patches.'))
->setEnumOptions(
- array('unified' => 'unified', 'git' => 'git')),
+ array(
+ 'unified' => pht('Unified'),
+ 'git' => pht('Git'),
+ )),
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 15, 11:55 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7704547
Default Alt Text
D18156.id43682.diff (10 KB)
Attached To
Mode
D18156: Convert "enum" and "string" config options to new modular option types
Attached
Detach File
Event Timeline
Log In to Comment