2012-03-31 01:23:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the type of a PHID. Returns
|
|
|
|
* PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN if it fails to look up the type
|
|
|
|
*
|
|
|
|
* @param phid Anything.
|
|
|
|
* @return A value from PhabricatorPHIDConstants (ideally)
|
|
|
|
*/
|
|
|
|
function phid_get_type($phid) {
|
|
|
|
$matches = null;
|
|
|
|
if (is_string($phid) && preg_match('/^PHID-([^-]{4})-/', $phid, $matches)) {
|
|
|
|
return $matches[1];
|
|
|
|
}
|
|
|
|
return PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-22 18:26:26 +02:00
|
|
|
* Group a list of phids by type.
|
2012-03-31 01:23:35 +02:00
|
|
|
*
|
|
|
|
* @param phids array of phids
|
|
|
|
* @return map of phid type => list of phids
|
|
|
|
*/
|
|
|
|
function phid_group_by_type($phids) {
|
|
|
|
$result = array();
|
|
|
|
foreach ($phids as $phid) {
|
|
|
|
$type = phid_get_type($phid);
|
|
|
|
$result[$type][] = $phid;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2012-12-11 23:00:21 +01:00
|
|
|
|
|
|
|
function phid_get_subtype($phid) {
|
|
|
|
if (isset($phid[14]) && ($phid[14] == '-')) {
|
|
|
|
return substr($phid, 10, 4);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|