1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-03 11:21:01 +01:00

Specialize list<string> in config

Summary: Specialize editing, display and validation of list<string> options.

Test Plan: Edited, viewed and validated "environment.append-paths".

Reviewers: codeblock, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2255

Differential Revision: https://secure.phabricator.com/D4319
This commit is contained in:
epriestley 2013-01-02 14:02:31 -08:00
parent cff043a800
commit db21319b39
3 changed files with 38 additions and 2 deletions

View file

@ -226,6 +226,9 @@ final class PhabricatorConfigEditController
case 'string':
$set_value = (string)$value;
break;
case 'list<string>':
$set_value = $request->getStrList('value');
break;
case 'bool':
switch ($value) {
case 'true':
@ -281,6 +284,8 @@ final class PhabricatorConfigEditController
return $value;
case 'bool':
return $value ? 'true' : 'false';
case 'list<string>':
return implode("\n", nonempty($value, array()));
default:
return $this->prettyPrintJSON($value);
}
@ -306,6 +311,10 @@ final class PhabricatorConfigEditController
'false' => idx($option->getOptions(), 1),
));
break;
case 'list<string>':
$control = id(new AphrontFormTextAreaControl())
->setCaption(pht('Separate values with newlines or commas.'));
break;
default:
$control = id(new AphrontFormTextAreaControl())
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
@ -340,7 +349,7 @@ final class PhabricatorConfigEditController
if ($value === null) {
$value = '<em>'.pht('(empty)').'</em>';
} else {
$value = phutil_escape_html($value);
$value = nl2br(phutil_escape_html($value));
}
$table[] = '<tr>';

View file

@ -41,6 +41,32 @@ abstract class PhabricatorApplicationConfigOptions extends Phobject {
$option->getKey()));
}
break;
case 'list<string>':
$valid = true;
if (!is_array($value)) {
throw new PhabricatorConfigValidationException(
pht(
"Option '%s' must be a list of strings, but value is not a ".
"an array.",
$option->getKey()));
}
if ($value && array_keys($value) != range(0, count($value) - 1)) {
throw new PhabricatorConfigValidationException(
pht(
"Option '%s' must be a list of strings, but the value is a ".
"map with unnatural keys.",
$option->getKey()));
}
foreach ($value as $v) {
if (!is_string($v)) {
throw new PhabricatorConfigValidationException(
pht(
"Option '%s' must be a list of strings, but it contains one ".
"or more non-strings.",
$option->getKey()));
}
}
break;
case 'wild':
default:
break;

View file

@ -90,7 +90,8 @@ final class PhabricatorCoreConfigOptions
"'nobody'). Here you can add extra directories to the \$PATH ".
"environment variable, for when these binaries are in ".
"non-standard locations."))
->addExample('/usr/local/bin', 'Valid Setting'),
->addExample('/usr/local/bin', pht('Add One Path'))
->addExample("/usr/bin\n/usr/local/bin", pht('Add Multiple Paths')),
);
}