Differential D17440 Diff 41952 src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
Show All 26 Lines | if (!preg_match('/^[a-z]+\z/', $subtype)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Subtype "%s" is not valid: subtype keys may only contain '. | 'Subtype "%s" is not valid: subtype keys may only contain '. | ||||
'lowercase latin letters ("a" through "z").', | 'lowercase latin letters ("a" through "z").', | ||||
$subtype)); | $subtype)); | ||||
} | } | ||||
} | } | ||||
public static function validateConfiguration($config) { | |||||
if (!is_array($config)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Subtype configuration is invalid: it must be a list of subtype '. | |||||
'specifications.')); | |||||
} | |||||
$map = array(); | |||||
foreach ($config as $value) { | |||||
PhutilTypeSpec::checkMap( | |||||
$value, | |||||
array( | |||||
'key' => 'string', | |||||
'name' => 'string', | |||||
)); | |||||
$key = $value['key']; | |||||
self::validateSubtypeKey($key); | |||||
if (isset($map[$key])) { | |||||
throw new Exception( | |||||
pht( | |||||
'Subtype configuration is invalid: two subtypes use the same '. | |||||
'key ("%s"). Each subtype must have a unique key.', | |||||
$key)); | |||||
} | |||||
$map[$key] = true; | |||||
$name = $value['name']; | |||||
if (!strlen($name)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Subtype configuration is invalid: subtype with key "%s" has '. | |||||
'no name. Subtypes must have a name.', | |||||
$key)); | |||||
} | |||||
} | |||||
if (!isset($map[self::SUBTYPE_DEFAULT])) { | |||||
throw new Exception( | |||||
pht( | |||||
'Subtype configuration is invalid: there is no subtype defined '. | |||||
'with key "%s". This subtype is required and must be defined.', | |||||
self::SUBTYPE_DEFAULT)); | |||||
} | |||||
} | |||||
} | } |