[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/field/selector/ -> ReleephFieldSelector.php (source)

   1  <?php
   2  
   3  abstract class ReleephFieldSelector {
   4  
   5    final public function __construct() {
   6      // <empty>
   7    }
   8  
   9    abstract public function getFieldSpecifications();
  10  
  11    public function sortFieldsForCommitMessage(array $fields) {
  12      assert_instances_of($fields, 'ReleephFieldSpecification');
  13      return $fields;
  14    }
  15  
  16    protected static function selectFields(array $fields, array $classes) {
  17      assert_instances_of($fields, 'ReleephFieldSpecification');
  18  
  19      $map = array();
  20      foreach ($fields as $field) {
  21        $map[get_class($field)] = $field;
  22      }
  23  
  24      $result = array();
  25      foreach ($classes as $class) {
  26        $field = idx($map, $class);
  27        if (!$field) {
  28          throw new Exception(
  29            "Tried to select a in instance of '{$class}' but that field ".
  30            "is not configured for this project!");
  31        }
  32  
  33        if (idx($result, $class)) {
  34          throw new Exception(
  35            "You have asked to select the field '{$class}' ".
  36            "more than once!");
  37        }
  38  
  39        $result[$class] = $field;
  40      }
  41  
  42      return $result;
  43    }
  44  
  45  }


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