[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/fact/spec/ -> PhabricatorFactSpec.php (source)

   1  <?php
   2  
   3  abstract class PhabricatorFactSpec {
   4  
   5    const UNIT_COUNT = 'unit-count';
   6    const UNIT_EPOCH = 'unit-epoch';
   7  
   8    public static function newSpecsForFactTypes(
   9      array $engines,
  10      array $fact_types) {
  11      assert_instances_of($engines, 'PhabricatorFactEngine');
  12  
  13      $map = array();
  14      foreach ($engines as $engine) {
  15        $specs = $engine->getFactSpecs($fact_types);
  16        $specs = mpull($specs, null, 'getType');
  17        $map += $specs;
  18      }
  19  
  20      foreach ($fact_types as $type) {
  21        if (empty($map[$type])) {
  22          $map[$type] = new PhabricatorFactSimpleSpec($type);
  23        }
  24      }
  25  
  26      return $map;
  27    }
  28  
  29    abstract public function getType();
  30  
  31    public function getUnit() {
  32      return null;
  33    }
  34  
  35    public function getName() {
  36      $type = $this->getType();
  37      return "Fact ({$type})";
  38    }
  39  
  40    public function formatValueForDisplay(PhabricatorUser $user, $value) {
  41      $unit = $this->getUnit();
  42      switch ($unit) {
  43        case self::UNIT_COUNT:
  44          return number_format($value);
  45        case self::UNIT_EPOCH:
  46          return phabricator_datetime($value, $user);
  47        default:
  48          return $value;
  49      }
  50    }
  51  
  52  }


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