diff --git a/src/applications/flag/query/flag/PhabricatorFlagQuery.php b/src/applications/flag/query/flag/PhabricatorFlagQuery.php index e952ec9352..78c6aa6b0c 100644 --- a/src/applications/flag/query/flag/PhabricatorFlagQuery.php +++ b/src/applications/flag/query/flag/PhabricatorFlagQuery.php @@ -68,7 +68,7 @@ final class PhabricatorFlagQuery { return id(new PhabricatorFlag())->loadOneWhere( 'ownerPHID = %s AND type = %s AND objectPHID = %s', $user->getPHID(), - PhabricatorObjectHandleData::lookupType($object_phid), + phid_get_type($object_phid), $object_phid); } diff --git a/src/applications/flag/query/flag/__init__.php b/src/applications/flag/query/flag/__init__.php index 30e59cd290..82541230a2 100644 --- a/src/applications/flag/query/flag/__init__.php +++ b/src/applications/flag/query/flag/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'applications/flag/storage/flag'); phutil_require_module('phabricator', 'applications/phid/handle/data'); +phutil_require_module('phabricator', 'applications/phid/utils'); phutil_require_module('phabricator', 'storage/qsprintf'); phutil_require_module('phabricator', 'storage/queryfx'); diff --git a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php index 8db0cec1c6..1aced1f81f 100644 --- a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php @@ -32,7 +32,7 @@ final class PhabricatorObjectHandleData { public function loadObjects() { $types = array(); foreach ($this->phids as $phid) { - $type = self::lookupType($phid); + $type = phid_get_type($phid); $types[$type][] = $phid; } @@ -98,11 +98,7 @@ final class PhabricatorObjectHandleData { public function loadHandles() { - $types = array(); - foreach ($this->phids as $phid) { - $type = self::lookupType($phid); - $types[$type][] = $phid; - } + $types = phid_group_by_type($this->phids); $handles = array(); @@ -497,13 +493,4 @@ final class PhabricatorObjectHandleData { return $handles; } - - public static function lookupType($phid) { - $matches = null; - if (preg_match('/^PHID-([^-]{4})-/', $phid, $matches)) { - return $matches[1]; - } - return PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN; - } - } diff --git a/src/applications/phid/handle/data/__init__.php b/src/applications/phid/handle/data/__init__.php index 7e7e93e86b..59fd9a6be7 100644 --- a/src/applications/phid/handle/data/__init__.php +++ b/src/applications/phid/handle/data/__init__.php @@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'applications/maniphest/constants/status'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'applications/phid/handle'); phutil_require_module('phabricator', 'applications/phid/handle/const/status'); +phutil_require_module('phabricator', 'applications/phid/utils'); phutil_require_module('phabricator', 'applications/phriction/storage/document'); phutil_require_module('phabricator', 'applications/repository/constants/repositorytype'); phutil_require_module('phabricator', 'applications/repository/storage/repository'); diff --git a/src/applications/phid/utils/__init__.php b/src/applications/phid/utils/__init__.php new file mode 100644 index 0000000000..3e6d3c3113 --- /dev/null +++ b/src/applications/phid/utils/__init__.php @@ -0,0 +1,12 @@ + [PHID-USER-1, PHID-USER-2], + * PhabricatorPHIDConstants::PHID_TYPE_PROJ => [PHID-PROJ-3]] + * + * @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; +}