@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 38 lines 922 B view raw
1<?php 2 3/** 4 * Look up the type of a PHID. Returns 5 * PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN if it fails to look up the type 6 * 7 * @param string $phid A PHID of anything. 8 * @return string A value from PhabricatorPHIDConstants (ideally) 9 */ 10function phid_get_type($phid) { 11 $matches = null; 12 if (is_string($phid) && preg_match('/^PHID-([^-]{4})-/', $phid, $matches)) { 13 return $matches[1]; 14 } 15 return PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN; 16} 17 18/** 19 * Group a list of phids by type. 20 * 21 * @param array $phids Array of PHIDs. 22 * @return array Mapping of phid type => list of phids 23 */ 24function phid_group_by_type($phids) { 25 $result = array(); 26 foreach ($phids as $phid) { 27 $type = phid_get_type($phid); 28 $result[$type][] = $phid; 29 } 30 return $result; 31} 32 33function phid_get_subtype($phid) { 34 if (isset($phid[14]) && ($phid[14] == '-')) { 35 return substr($phid, 10, 4); 36 } 37 return null; 38}