[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phid/ -> utils.php (source)

   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   phid Anything.
   8   * @return  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];
  14    }
  15    return PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN;
  16  }
  17  
  18  /**
  19   * Group a list of phids by type.
  20   *
  21   * @param   phids array of phids
  22   * @return  map of phid type => list of phids
  23   */
  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;
  29    }
  30    return $result;
  31  }
  32  
  33  function phid_get_subtype($phid) {
  34    if (isset($phid[14]) && ($phid[14] == '-')) {
  35      return substr($phid, 10, 4);
  36    }
  37    return null;
  38  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1