1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 03:02:43 +01:00
phorge-phorge/src/applications/phid/utils.php
epriestley 69d5a9af58 Use Application PHIDs in Projects
Summary: Ref T2715. Move Projects to the new stuff.

Test Plan: Used `phid.query` to load projects.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6526
2013-07-22 12:17:53 -07:00

38 lines
877 B
PHP

<?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;
}
/**
* Group a list of phids by type.
*
* @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;
}
function phid_get_subtype($phid) {
if (isset($phid[14]) && ($phid[14] == '-')) {
return substr($phid, 10, 4);
}
return null;
}