4 * Look up the type of a PHID. Returns
5 * PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN if it fails to look up the type
7 * @param phid Anything.
8 * @return string A value from PhabricatorPHIDConstants (ideally)
10 function phid_get_type($phid) {
12 if (is_string($phid) && preg_match('/^PHID-([^-]{4})-/', $phid, $matches)) {
15 return PhabricatorPHIDConstants
::PHID_TYPE_UNKNOWN
;
19 * Group a list of phids by type.
21 * @param phids array of phids
22 * @return map of phid type => list of phids
24 function phid_group_by_type($phids) {
26 foreach ($phids as $phid) {
27 $type = phid_get_type($phid);
28 $result[$type][] = $phid;
33 function phid_get_subtype($phid) {
34 if (isset($phid[14]) && ($phid[14] == '-')) {
35 return substr($phid, 10, 4);