[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/data/ -> DiffusionPathChange.php (source)

   1  <?php
   2  
   3  final class DiffusionPathChange {
   4  
   5    private $path;
   6    private $commitIdentifier;
   7    private $commit;
   8    private $commitData;
   9  
  10    private $changeType;
  11    private $fileType;
  12    private $targetPath;
  13    private $targetCommitIdentifier;
  14    private $awayPaths = array();
  15  
  16    final public function setPath($path) {
  17      $this->path = $path;
  18      return $this;
  19    }
  20  
  21    final public function getPath() {
  22      return $this->path;
  23    }
  24  
  25    public function setChangeType($change_type) {
  26      $this->changeType = $change_type;
  27      return $this;
  28    }
  29  
  30    public function getChangeType() {
  31      return $this->changeType;
  32    }
  33  
  34    public function setFileType($file_type) {
  35      $this->fileType = $file_type;
  36      return $this;
  37    }
  38  
  39    public function getFileType() {
  40      return $this->fileType;
  41    }
  42  
  43    public function setTargetPath($target_path) {
  44      $this->targetPath = $target_path;
  45      return $this;
  46    }
  47  
  48    public function getTargetPath() {
  49      return $this->targetPath;
  50    }
  51  
  52    public function setAwayPaths(array $away_paths) {
  53      $this->awayPaths = $away_paths;
  54      return $this;
  55    }
  56  
  57    public function getAwayPaths() {
  58      return $this->awayPaths;
  59    }
  60  
  61    final public function setCommitIdentifier($commit) {
  62      $this->commitIdentifier = $commit;
  63      return $this;
  64    }
  65  
  66    final public function getCommitIdentifier() {
  67      return $this->commitIdentifier;
  68    }
  69  
  70    final public function setTargetCommitIdentifier($target_commit_identifier) {
  71      $this->targetCommitIdentifier = $target_commit_identifier;
  72      return $this;
  73    }
  74  
  75    final public function getTargetCommitIdentifier() {
  76      return $this->targetCommitIdentifier;
  77    }
  78  
  79    final public function setCommit($commit) {
  80      $this->commit = $commit;
  81      return $this;
  82    }
  83  
  84    final public function getCommit() {
  85      return $this->commit;
  86    }
  87  
  88    final public function setCommitData($commit_data) {
  89      $this->commitData = $commit_data;
  90      return $this;
  91    }
  92  
  93    final public function getCommitData() {
  94      return $this->commitData;
  95    }
  96  
  97  
  98    final public function getEpoch() {
  99      if ($this->getCommit()) {
 100        return $this->getCommit()->getEpoch();
 101      }
 102      return null;
 103    }
 104  
 105    final public function getAuthorName() {
 106      if ($this->getCommitData()) {
 107        return $this->getCommitData()->getAuthorName();
 108      }
 109      return null;
 110    }
 111  
 112    final public function getSummary() {
 113      if (!$this->getCommitData()) {
 114        return null;
 115      }
 116      $message = $this->getCommitData()->getCommitMessage();
 117      $first = idx(explode("\n", $message), 0);
 118      return substr($first, 0, 80);
 119    }
 120  
 121    final public static function convertToArcanistChanges(array $changes) {
 122      assert_instances_of($changes, 'DiffusionPathChange');
 123      $direct = array();
 124      $result = array();
 125      foreach ($changes as $path) {
 126        $change = new ArcanistDiffChange();
 127        $change->setCurrentPath($path->getPath());
 128        $direct[] = $path->getPath();
 129        $change->setType($path->getChangeType());
 130        $file_type = $path->getFileType();
 131        if ($file_type == DifferentialChangeType::FILE_NORMAL) {
 132          $file_type = DifferentialChangeType::FILE_TEXT;
 133        }
 134        $change->setFileType($file_type);
 135        $change->setOldPath($path->getTargetPath());
 136        foreach ($path->getAwayPaths() as $away_path) {
 137          $change->addAwayPath($away_path);
 138        }
 139        $result[$path->getPath()] = $change;
 140      }
 141  
 142      return array_select_keys($result, $direct);
 143    }
 144  
 145    final public static function convertToDifferentialChangesets(
 146      PhabricatorUser $user,
 147      array $changes) {
 148      assert_instances_of($changes, 'DiffusionPathChange');
 149      $arcanist_changes = self::convertToArcanistChanges($changes);
 150      $diff = DifferentialDiff::newFromRawChanges($user, $arcanist_changes);
 151      return $diff->getChangesets();
 152    }
 153  
 154    public function toDictionary() {
 155      $commit = $this->getCommit();
 156      if ($commit) {
 157        $commit_dict = $commit->toDictionary();
 158      } else {
 159        $commit_dict = array();
 160      }
 161      $commit_data = $this->getCommitData();
 162      if ($commit_data) {
 163        $commit_data_dict = $commit_data->toDictionary();
 164      } else {
 165        $commit_data_dict = array();
 166      }
 167      return array(
 168        'path' => $this->getPath(),
 169        'commitIdentifier' => $this->getCommitIdentifier(),
 170        'commit' => $commit_dict,
 171        'commitData' => $commit_data_dict,
 172        'fileType' => $this->getFileType(),
 173        'changeType' => $this->getChangeType(),
 174        'targetPath' =>  $this->getTargetPath(),
 175        'targetCommitIdentifier' => $this->getTargetCommitIdentifier(),
 176        'awayPaths' => $this->getAwayPaths(),
 177      );
 178    }
 179  
 180    public static function newFromConduit(array $dicts) {
 181      $results = array();
 182      foreach ($dicts as $dict) {
 183        $commit = PhabricatorRepositoryCommit::newFromDictionary($dict['commit']);
 184        $commit_data =
 185          PhabricatorRepositoryCommitData::newFromDictionary(
 186            $dict['commitData']);
 187        $results[] = id(new DiffusionPathChange())
 188          ->setPath($dict['path'])
 189          ->setCommitIdentifier($dict['commitIdentifier'])
 190          ->setCommit($commit)
 191          ->setCommitData($commit_data)
 192          ->setFileType($dict['fileType'])
 193          ->setChangeType($dict['changeType'])
 194          ->setTargetPath($dict['targetPath'])
 195          ->setTargetCommitIdentifier($dict['targetCommitIdentifier'])
 196          ->setAwayPaths($dict['awayPaths']);
 197      }
 198      return $results;
 199    }
 200  
 201  }


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