Differential D18155 Diff 43701 src/applications/config/option/PhabricatorApplicationConfigOptions.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/option/PhabricatorApplicationConfigOptions.php
Show All 14 Lines | public function validateOption(PhabricatorConfigOption $option, $value) { | ||||
if ($value === $option->getDefault()) { | if ($value === $option->getDefault()) { | ||||
return; | return; | ||||
} | } | ||||
if ($value === null) { | if ($value === null) { | ||||
return; | return; | ||||
} | } | ||||
$type = $option->newOptionType(); | |||||
if ($type) { | |||||
try { | |||||
$type->validateStoredValue($option, $value); | |||||
} catch (PhabricatorConfigValidationException $ex) { | |||||
throw $ex; | |||||
} catch (Exception $ex) { | |||||
// If custom validators threw exceptions other than validation | |||||
// exceptions, convert them to validation exceptions so we repair the | |||||
// configuration and raise an error. | |||||
throw new PhabricatorConfigValidationException($ex->getMessage()); | |||||
} | |||||
} | |||||
if ($option->isCustomType()) { | if ($option->isCustomType()) { | ||||
try { | try { | ||||
return $option->getCustomObject()->validateOption($option, $value); | return $option->getCustomObject()->validateOption($option, $value); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
// If custom validators threw exceptions, convert them to configuation | |||||
// validation exceptions so we repair the configuration and raise | |||||
// an error. | |||||
throw new PhabricatorConfigValidationException($ex->getMessage()); | throw new PhabricatorConfigValidationException($ex->getMessage()); | ||||
} | } | ||||
} | } | ||||
switch ($option->getType()) { | switch ($option->getType()) { | ||||
case 'bool': | case 'bool': | ||||
if ($value !== true && | if ($value !== true && | ||||
$value !== false) { | $value !== false) { | ||||
throw new PhabricatorConfigValidationException( | throw new PhabricatorConfigValidationException( | ||||
pht( | pht( | ||||
"Option '%s' is of type bool, but value is not true or false.", | "Option '%s' is of type bool, but value is not true or false.", | ||||
$option->getKey())); | $option->getKey())); | ||||
} | } | ||||
break; | break; | ||||
case 'int': | |||||
if (!is_int($value)) { | |||||
throw new PhabricatorConfigValidationException( | |||||
pht( | |||||
"Option '%s' is of type int, but value is not an integer.", | |||||
$option->getKey())); | |||||
} | |||||
break; | |||||
case 'string': | case 'string': | ||||
if (!is_string($value)) { | if (!is_string($value)) { | ||||
throw new PhabricatorConfigValidationException( | throw new PhabricatorConfigValidationException( | ||||
pht( | pht( | ||||
"Option '%s' is of type string, but value is not a string.", | "Option '%s' is of type string, but value is not a string.", | ||||
$option->getKey())); | $option->getKey())); | ||||
} | } | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines |