Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/constants/ManiphestTaskPriority.php
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | public static function validateConfiguration($config) { | ||||
if (!is_array($config)) { | if (!is_array($config)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Configuration is not valid. Maniphest priority configurations '. | 'Configuration is not valid. Maniphest priority configurations '. | ||||
'must be dictionaries.', | 'must be dictionaries.', | ||||
$config)); | $config)); | ||||
} | } | ||||
$all_keywords = array(); | |||||
foreach ($config as $key => $value) { | foreach ($config as $key => $value) { | ||||
if (!ctype_digit((string)$key)) { | if (!ctype_digit((string)$key)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Key "%s" is not a valid priority constant. Priority constants '. | 'Key "%s" is not a valid priority constant. Priority constants '. | ||||
'must be nonnegative integers.', | 'must be nonnegative integers.', | ||||
$key)); | $key)); | ||||
} | } | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Value for key "%s" should be a dictionary.', | 'Value for key "%s" should be a dictionary.', | ||||
$key)); | $key)); | ||||
} | } | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$value, | $value, | ||||
array( | array( | ||||
'name' => 'string', | 'name' => 'string', | ||||
'keywords' => 'list<string>', | |||||
'short' => 'optional string', | 'short' => 'optional string', | ||||
'color' => 'optional string', | 'color' => 'optional string', | ||||
'keywords' => 'list<string>', | |||||
'disabled' => 'optional bool', | 'disabled' => 'optional bool', | ||||
)); | )); | ||||
$keywords = $value['keywords']; | $keywords = $value['keywords']; | ||||
foreach ($keywords as $keyword) { | foreach ($keywords as $keyword) { | ||||
if (!self::isValidPriorityKeyword($keyword)) { | if (!self::isValidPriorityKeyword($keyword)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Key "%s" is not a valid priority keyword. Priority keywords '. | 'Key "%s" is not a valid priority keyword. Priority keywords '. | ||||
'must be 1-64 alphanumeric characters and cannot be '. | 'must be 1-64 alphanumeric characters and cannot be '. | ||||
'exclusively digits. For example, "%s" or "%s" are '. | 'exclusively digits. For example, "%s" or "%s" are '. | ||||
'reasonable choices.', | 'reasonable choices.', | ||||
$keyword, | $keyword, | ||||
'low', | 'low', | ||||
'critical')); | 'critical')); | ||||
} | } | ||||
if (isset($all_keywords[$keyword])) { | |||||
throw new Exception( | |||||
pht( | |||||
'Two different task priorities ("%s" and "%s") have the same '. | |||||
'keyword ("%s"). Keywords must uniquely identify priorities.', | |||||
$value['name'], | |||||
$all_keywords[$keyword], | |||||
$keyword)); | |||||
} | |||||
$all_keywords[$keyword] = $value['name']; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |