Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / phid / utils.php
blob152a54728464b9577171da02e08d3f3b37279376
1 <?php
3 /**
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)
9 */
10 function phid_get_type($phid) {
11 $matches = null;
12 if (is_string($phid) && preg_match('/^PHID-([^-]{4})-/', $phid, $matches)) {
13 return $matches[1];
15 return PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN;
18 /**
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) {
25 $result = array();
26 foreach ($phids as $phid) {
27 $type = phid_get_type($phid);
28 $result[$type][] = $phid;
30 return $result;
33 function phid_get_subtype($phid) {
34 if (isset($phid[14]) && ($phid[14] == '-')) {
35 return substr($phid, 10, 4);
37 return null;