1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Add some core phid functions

Summary: As title

Test Plan: hit diffcamp, owners to test HandleData

Reviewers: epriestley, btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D2063
This commit is contained in:
mkedia 2012-03-30 16:23:35 -07:00
parent 5ee1341b97
commit be3c179561
6 changed files with 71 additions and 16 deletions

View file

@ -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);
}

View file

@ -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');

View file

@ -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;
}
}

View file

@ -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');

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/phid/constants');
phutil_require_source('utils.php');

View file

@ -0,0 +1,54 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 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. Given:
*
* phid_group_by_type([PHID-USER-1, PHID-USER-2, PHID-PROJ-3])
*
* phid_group_by_type would return:
*
* [PhabricatorPHIDConstants::PHID_TYPE_USER => [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;
}