[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/herald/adapter/ -> HeraldDifferentialDiffAdapter.php (source)

   1  <?php
   2  
   3  final class HeraldDifferentialDiffAdapter extends HeraldDifferentialAdapter {
   4  
   5    public function getAdapterApplicationClass() {
   6      return 'PhabricatorDifferentialApplication';
   7    }
   8  
   9    protected function loadChangesets() {
  10      return $this->loadChangesetsWithHunks();
  11    }
  12  
  13    protected function loadChangesetsWithHunks() {
  14      return $this->getDiff()->getChangesets();
  15    }
  16  
  17    public function getObject() {
  18      return $this->getDiff();
  19    }
  20  
  21    public function getAdapterContentType() {
  22      return 'differential.diff';
  23    }
  24  
  25    public function getAdapterContentName() {
  26      return pht('Differential Diffs');
  27    }
  28  
  29    public function getAdapterContentDescription() {
  30      return pht(
  31        "React to new diffs being uploaded, before writes occur.\n".
  32        "These rules can reject diffs before they are written to permanent ".
  33        "storage, to prevent users from accidentally uploading private keys or ".
  34        "other sensitive information.");
  35    }
  36  
  37    public function supportsRuleType($rule_type) {
  38      switch ($rule_type) {
  39        case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
  40          return true;
  41        case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
  42        case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
  43        default:
  44          return false;
  45      }
  46    }
  47  
  48    public function getFields() {
  49      return array_merge(
  50        array(
  51          self::FIELD_AUTHOR,
  52          self::FIELD_AUTHOR_PROJECTS,
  53          self::FIELD_REPOSITORY,
  54          self::FIELD_REPOSITORY_PROJECTS,
  55          self::FIELD_DIFF_FILE,
  56          self::FIELD_DIFF_CONTENT,
  57          self::FIELD_DIFF_ADDED_CONTENT,
  58          self::FIELD_DIFF_REMOVED_CONTENT,
  59        ),
  60        parent::getFields());
  61    }
  62  
  63    public function getRepetitionOptions() {
  64      return array(
  65        HeraldRepetitionPolicyConfig::FIRST,
  66      );
  67    }
  68  
  69    public function getPHID() {
  70      return $this->getObject()->getPHID();
  71    }
  72  
  73    public function getHeraldName() {
  74      return pht('New Diff');
  75    }
  76  
  77    public function getActionNameMap($rule_type) {
  78      return array(
  79        self::ACTION_BLOCK => pht('Block diff with message'),
  80      );
  81    }
  82  
  83    public function getHeraldField($field) {
  84      switch ($field) {
  85        case self::FIELD_AUTHOR:
  86          return $this->getObject()->getAuthorPHID();
  87          break;
  88        case self::FIELD_AUTHOR_PROJECTS:
  89          $author_phid = $this->getHeraldField(self::FIELD_AUTHOR);
  90          if (!$author_phid) {
  91            return array();
  92          }
  93  
  94          $projects = id(new PhabricatorProjectQuery())
  95            ->setViewer(PhabricatorUser::getOmnipotentUser())
  96            ->withMemberPHIDs(array($author_phid))
  97            ->execute();
  98  
  99          return mpull($projects, 'getPHID');
 100        case self::FIELD_DIFF_FILE:
 101          return $this->loadAffectedPaths();
 102        case self::FIELD_REPOSITORY:
 103          $repository = $this->loadRepository();
 104          if (!$repository) {
 105            return null;
 106          }
 107          return $repository->getPHID();
 108        case self::FIELD_REPOSITORY_PROJECTS:
 109          $repository = $this->loadRepository();
 110          if (!$repository) {
 111            return array();
 112          }
 113          return $repository->getProjectPHIDs();
 114        case self::FIELD_DIFF_CONTENT:
 115          return $this->loadContentDictionary();
 116        case self::FIELD_DIFF_ADDED_CONTENT:
 117          return $this->loadAddedContentDictionary();
 118        case self::FIELD_DIFF_REMOVED_CONTENT:
 119          return $this->loadRemovedContentDictionary();
 120      }
 121  
 122      return parent::getHeraldField($field);
 123    }
 124  
 125    public function getActions($rule_type) {
 126      switch ($rule_type) {
 127        case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
 128          return array_merge(
 129            array(
 130              self::ACTION_BLOCK,
 131              self::ACTION_NOTHING,
 132            ),
 133            parent::getActions($rule_type));
 134      }
 135    }
 136  
 137    public function applyHeraldEffects(array $effects) {
 138      assert_instances_of($effects, 'HeraldEffect');
 139  
 140      $result = array();
 141      foreach ($effects as $effect) {
 142        $action = $effect->getAction();
 143        switch ($action) {
 144          case self::ACTION_NOTHING:
 145            $result[] = new HeraldApplyTranscript(
 146              $effect,
 147              true,
 148              pht('Did nothing.'));
 149            break;
 150          case self::ACTION_BLOCK:
 151            $result[] = new HeraldApplyTranscript(
 152              $effect,
 153              true,
 154              pht('Blocked diff.'));
 155            break;
 156          default:
 157            throw new Exception(pht('No rules to handle action "%s"!', $action));
 158        }
 159      }
 160  
 161      return $result;
 162    }
 163  
 164  }


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