Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/view/DiffusionSourceLinkView.php
12242 views
1
<?php
2
3
final class DiffusionSourceLinkView
4
extends AphrontView {
5
6
private $repository;
7
private $text;
8
private $uri;
9
private $blob;
10
private $blobMap;
11
private $refName;
12
private $path;
13
private $line;
14
private $commit;
15
16
public function setRepository($repository) {
17
$this->repository = $repository;
18
$this->blobMap = null;
19
return $this;
20
}
21
22
public function getRepository() {
23
return $this->repository;
24
}
25
26
public function setText($text) {
27
$this->text = $text;
28
return $this;
29
}
30
31
public function getText() {
32
return $this->text;
33
}
34
35
public function setURI($uri) {
36
$this->uri = $uri;
37
return $this;
38
}
39
40
public function getURI() {
41
return $this->uri;
42
}
43
44
public function setBlob($blob) {
45
$this->blob = $blob;
46
$this->blobMap = null;
47
return $this;
48
}
49
50
public function getBlob() {
51
return $this->blob;
52
}
53
54
public function setRefName($ref_name) {
55
$this->refName = $ref_name;
56
return $this;
57
}
58
59
public function getRefName() {
60
return $this->refName;
61
}
62
63
public function setPath($path) {
64
$this->path = $path;
65
return $this;
66
}
67
68
public function getPath() {
69
return $this->path;
70
}
71
72
public function setCommit($commit) {
73
$this->commit = $commit;
74
return $this;
75
}
76
77
public function getCommit() {
78
return $this->commit;
79
}
80
81
public function setLine($line) {
82
$this->line = $line;
83
return $this;
84
}
85
86
public function getLine() {
87
return $this->line;
88
}
89
90
public function getDisplayPath() {
91
if ($this->path !== null) {
92
return $this->path;
93
}
94
95
return $this->getBlobPath();
96
}
97
98
public function getDisplayRefName() {
99
if ($this->refName !== null) {
100
return $this->refName;
101
}
102
103
return $this->getBlobRefName();
104
}
105
106
public function getDisplayCommit() {
107
if ($this->commit !== null) {
108
return $this->commit;
109
}
110
111
return $this->getBlobCommit();
112
}
113
114
public function getDisplayLine() {
115
if ($this->line !== null) {
116
return $this->line;
117
}
118
119
return $this->getBlobLine();
120
}
121
122
private function getBlobPath() {
123
return idx($this->getBlobMap(), 'path');
124
}
125
126
private function getBlobRefName() {
127
return idx($this->getBlobMap(), 'branch');
128
}
129
130
private function getBlobLine() {
131
return idx($this->getBlobMap(), 'line');
132
}
133
134
private function getBlobCommit() {
135
return idx($this->getBlobMap(), 'commit');
136
}
137
138
private function getBlobMap() {
139
if ($this->blobMap === null) {
140
$repository = $this->getRepository();
141
$blob = $this->blob;
142
143
if ($repository && ($blob !== null)) {
144
$map = DiffusionRequest::parseRequestBlob(
145
$blob,
146
$repository->supportsRefs());
147
} else {
148
$map = array();
149
}
150
151
$this->blobMap = $map;
152
}
153
154
return $this->blobMap;
155
}
156
157
public function render() {
158
$repository = $this->getRepository();
159
$uri = $this->getURI();
160
161
$color = 'blue';
162
$icon = 'fa-file-text-o';
163
164
$text = $this->getText();
165
if (!strlen($text)) {
166
$path = $this->getDisplayPath();
167
168
$line = $this->getDisplayLine();
169
if ($line !== null) {
170
$path = pht('%s:%s', $path, $line);
171
}
172
173
if ($repository) {
174
$path = pht('%s %s', $repository->getMonogram(), $path);
175
}
176
177
if ($repository && $repository->supportsRefs()) {
178
$default_ref = $repository->getDefaultBranch();
179
} else {
180
$default_ref = null;
181
}
182
183
$ref_name = $this->getDisplayRefName();
184
if ($ref_name === $default_ref) {
185
$ref_name = null;
186
}
187
188
$commit = $this->getDisplayCommit();
189
if ($ref_name !== null && $commit !== null) {
190
$text = pht('%s (on %s at %s)', $path, $ref_name, $commit);
191
} else if ($ref_name !== null) {
192
$text = pht('%s (on %s)', $path, $ref_name);
193
} else if ($commit !== null) {
194
$text = pht('%s (at %s)', $path, $commit);
195
} else {
196
$text = $path;
197
}
198
}
199
200
return id(new PHUITagView())
201
->setType(PHUITagView::TYPE_SHADE)
202
->setColor($color)
203
->setIcon($icon)
204
->setHref($uri)
205
->setName($text);
206
}
207
208
}
209
210