2011-01-23 06:09:13 +01:00
|
|
|
<?php
|
|
|
|
|
2015-06-15 10:02:26 +02:00
|
|
|
final class PhabricatorPHID extends Phobject {
|
2011-01-23 06:09:13 +01:00
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
public static function generateNewPHID($type, $subtype = null) {
|
2011-01-23 06:09:13 +01:00
|
|
|
if (!$type) {
|
2015-05-22 09:27:56 +02:00
|
|
|
throw new Exception(pht('Can not generate PHID with no type.'));
|
2011-01-23 06:09:13 +01:00
|
|
|
}
|
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
if ($subtype === null) {
|
|
|
|
$uniq_len = 20;
|
|
|
|
$type_str = "{$type}";
|
|
|
|
} else {
|
|
|
|
$uniq_len = 15;
|
|
|
|
$type_str = "{$type}-{$subtype}";
|
|
|
|
}
|
|
|
|
|
|
|
|
$uniq = Filesystem::readRandomCharacters($uniq_len);
|
|
|
|
return "PHID-{$type_str}-{$uniq}";
|
2011-01-23 06:09:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|