Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
4.2 kB · 208 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209<?php
final class DiffusionSourceLinkView extends AphrontView {
private $repository; private $text; private $uri; private $blob; private $blobMap; private $refName; private $path; private $line; private $commit;
public function setRepository($repository) { $this->repository = $repository; $this->blobMap = null; return $this; }
public function getRepository() { return $this->repository; }
public function setText($text) { $this->text = $text; return $this; }
public function getText() { return $this->text; }
public function setURI($uri) { $this->uri = $uri; return $this; }
public function getURI() { return $this->uri; }
public function setBlob($blob) { $this->blob = $blob; $this->blobMap = null; return $this; }
public function getBlob() { return $this->blob; }
public function setRefName($ref_name) { $this->refName = $ref_name; return $this; }
public function getRefName() { return $this->refName; }
public function setPath($path) { $this->path = $path; return $this; }
public function getPath() { return $this->path; }
public function setCommit($commit) { $this->commit = $commit; return $this; }
public function getCommit() { return $this->commit; }
public function setLine($line) { $this->line = $line; return $this; }
public function getLine() { return $this->line; }
public function getDisplayPath() { if ($this->path !== null) { return $this->path; }
return $this->getBlobPath(); }
public function getDisplayRefName() { if ($this->refName !== null) { return $this->refName; }
return $this->getBlobRefName(); }
public function getDisplayCommit() { if ($this->commit !== null) { return $this->commit; }
return $this->getBlobCommit(); }
public function getDisplayLine() { if ($this->line !== null) { return $this->line; }
return $this->getBlobLine(); }
private function getBlobPath() { return idx($this->getBlobMap(), 'path'); }
private function getBlobRefName() { return idx($this->getBlobMap(), 'branch'); }
private function getBlobLine() { return idx($this->getBlobMap(), 'line'); }
private function getBlobCommit() { return idx($this->getBlobMap(), 'commit'); }
private function getBlobMap() { if ($this->blobMap === null) { $repository = $this->getRepository(); $blob = $this->blob;
if ($repository && ($blob !== null)) { $map = DiffusionRequest::parseRequestBlob( $blob, $repository->supportsRefs()); } else { $map = array(); }
$this->blobMap = $map; }
return $this->blobMap; }
public function render() { $repository = $this->getRepository(); $uri = $this->getURI();
$color = 'blue'; $icon = 'fa-file-text-o';
$text = $this->getText(); if (!phutil_nonempty_string($text)) { $path = $this->getDisplayPath();
$line = $this->getDisplayLine(); if ($line !== null) { $path = pht('%s:%s', $path, $line); }
if ($repository) { $path = pht('%s %s', $repository->getMonogram(), $path); }
if ($repository && $repository->supportsRefs()) { $default_ref = $repository->getDefaultBranch(); } else { $default_ref = null; }
$ref_name = $this->getDisplayRefName(); if ($ref_name === $default_ref) { $ref_name = null; }
$commit = $this->getDisplayCommit(); if ($ref_name !== null && $commit !== null) { $text = pht('%s (on %s at %s)', $path, $ref_name, $commit); } else if ($ref_name !== null) { $text = pht('%s (on %s)', $path, $ref_name); } else if ($commit !== null) { $text = pht('%s (at %s)', $path, $commit); } else { $text = $path; } }
return id(new PHUITagView()) ->setType(PHUITagView::TYPE_SHADE) ->setColor($color) ->setIcon($icon) ->setHref($uri) ->setName($text); }
}