Path: blob/master/src/applications/diffusion/view/DiffusionSourceLinkView.php
12242 views
<?php12final class DiffusionSourceLinkView3extends AphrontView {45private $repository;6private $text;7private $uri;8private $blob;9private $blobMap;10private $refName;11private $path;12private $line;13private $commit;1415public function setRepository($repository) {16$this->repository = $repository;17$this->blobMap = null;18return $this;19}2021public function getRepository() {22return $this->repository;23}2425public function setText($text) {26$this->text = $text;27return $this;28}2930public function getText() {31return $this->text;32}3334public function setURI($uri) {35$this->uri = $uri;36return $this;37}3839public function getURI() {40return $this->uri;41}4243public function setBlob($blob) {44$this->blob = $blob;45$this->blobMap = null;46return $this;47}4849public function getBlob() {50return $this->blob;51}5253public function setRefName($ref_name) {54$this->refName = $ref_name;55return $this;56}5758public function getRefName() {59return $this->refName;60}6162public function setPath($path) {63$this->path = $path;64return $this;65}6667public function getPath() {68return $this->path;69}7071public function setCommit($commit) {72$this->commit = $commit;73return $this;74}7576public function getCommit() {77return $this->commit;78}7980public function setLine($line) {81$this->line = $line;82return $this;83}8485public function getLine() {86return $this->line;87}8889public function getDisplayPath() {90if ($this->path !== null) {91return $this->path;92}9394return $this->getBlobPath();95}9697public function getDisplayRefName() {98if ($this->refName !== null) {99return $this->refName;100}101102return $this->getBlobRefName();103}104105public function getDisplayCommit() {106if ($this->commit !== null) {107return $this->commit;108}109110return $this->getBlobCommit();111}112113public function getDisplayLine() {114if ($this->line !== null) {115return $this->line;116}117118return $this->getBlobLine();119}120121private function getBlobPath() {122return idx($this->getBlobMap(), 'path');123}124125private function getBlobRefName() {126return idx($this->getBlobMap(), 'branch');127}128129private function getBlobLine() {130return idx($this->getBlobMap(), 'line');131}132133private function getBlobCommit() {134return idx($this->getBlobMap(), 'commit');135}136137private function getBlobMap() {138if ($this->blobMap === null) {139$repository = $this->getRepository();140$blob = $this->blob;141142if ($repository && ($blob !== null)) {143$map = DiffusionRequest::parseRequestBlob(144$blob,145$repository->supportsRefs());146} else {147$map = array();148}149150$this->blobMap = $map;151}152153return $this->blobMap;154}155156public function render() {157$repository = $this->getRepository();158$uri = $this->getURI();159160$color = 'blue';161$icon = 'fa-file-text-o';162163$text = $this->getText();164if (!strlen($text)) {165$path = $this->getDisplayPath();166167$line = $this->getDisplayLine();168if ($line !== null) {169$path = pht('%s:%s', $path, $line);170}171172if ($repository) {173$path = pht('%s %s', $repository->getMonogram(), $path);174}175176if ($repository && $repository->supportsRefs()) {177$default_ref = $repository->getDefaultBranch();178} else {179$default_ref = null;180}181182$ref_name = $this->getDisplayRefName();183if ($ref_name === $default_ref) {184$ref_name = null;185}186187$commit = $this->getDisplayCommit();188if ($ref_name !== null && $commit !== null) {189$text = pht('%s (on %s at %s)', $path, $ref_name, $commit);190} else if ($ref_name !== null) {191$text = pht('%s (on %s)', $path, $ref_name);192} else if ($commit !== null) {193$text = pht('%s (at %s)', $path, $commit);194} else {195$text = $path;196}197}198199return id(new PHUITagView())200->setType(PHUITagView::TYPE_SHADE)201->setColor($color)202->setIcon($icon)203->setHref($uri)204->setName($text);205}206207}208209210