Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / differential / view / DifferentialLocalCommitsView.php
blob4ac2bc14b3964dab36c73ca00263bc83238ea0bb
1 <?php
3 final class DifferentialLocalCommitsView extends AphrontView {
5 private $localCommits;
6 private $commitsForLinks = array();
8 public function setLocalCommits($local_commits) {
9 $this->localCommits = $local_commits;
10 return $this;
13 public function setCommitsForLinks(array $commits) {
14 assert_instances_of($commits, 'PhabricatorRepositoryCommit');
15 $this->commitsForLinks = $commits;
16 return $this;
19 public function render() {
20 $viewer = $this->getViewer();
22 $local = $this->localCommits;
23 if (!$local) {
24 return null;
27 $has_tree = false;
28 $has_local = false;
30 foreach ($local as $commit) {
31 if (idx($commit, 'tree')) {
32 $has_tree = true;
34 if (idx($commit, 'local')) {
35 $has_local = true;
39 $rows = array();
40 foreach ($local as $commit) {
41 $row = array();
42 if (idx($commit, 'commit')) {
43 $commit_link = $this->buildCommitLink($commit['commit']);
44 } else if (isset($commit['rev'])) {
45 $commit_link = $this->buildCommitLink($commit['rev']);
46 } else {
47 $commit_link = null;
49 $row[] = $commit_link;
51 if ($has_tree) {
52 $row[] = $this->buildCommitLink($commit['tree']);
55 if ($has_local) {
56 $row[] = $this->buildCommitLink($commit['local']);
59 $parents = idx($commit, 'parents', array());
60 foreach ($parents as $k => $parent) {
61 if (is_array($parent)) {
62 $parent = idx($parent, 'rev');
64 $parents[$k] = $this->buildCommitLink($parent);
66 $parents = phutil_implode_html(phutil_tag('br'), $parents);
67 $row[] = $parents;
69 $author = nonempty(
70 idx($commit, 'user'),
71 idx($commit, 'author'));
72 $row[] = $author;
74 $message = idx($commit, 'message');
76 $summary = idx($commit, 'summary');
77 $summary = id(new PhutilUTF8StringTruncator())
78 ->setMaximumGlyphs(80)
79 ->truncateString($summary);
81 $view = new AphrontMoreView();
82 $view->setSome($summary);
84 if ($message && (trim($summary) != trim($message))) {
85 $view->setMore(phutil_escape_html_newlines($message));
88 $row[] = $view->render();
90 $date = nonempty(
91 idx($commit, 'date'),
92 idx($commit, 'time'));
93 if ($date) {
94 $date = phabricator_datetime($date, $viewer);
96 $row[] = $date;
98 $rows[] = $row;
101 $column_classes = array('');
102 if ($has_tree) {
103 $column_classes[] = '';
105 if ($has_local) {
106 $column_classes[] = '';
108 $column_classes[] = '';
109 $column_classes[] = '';
110 $column_classes[] = 'wide';
111 $column_classes[] = 'date';
112 $table = id(new AphrontTableView($rows))
113 ->setColumnClasses($column_classes);
114 $headers = array();
115 $headers[] = pht('Commit');
116 if ($has_tree) {
117 $headers[] = pht('Tree');
119 if ($has_local) {
120 $headers[] = pht('Local');
122 $headers[] = pht('Parents');
123 $headers[] = pht('Author');
124 $headers[] = pht('Summary');
125 $headers[] = pht('Date');
126 $table->setHeaders($headers);
128 return $table;
131 private static function formatCommit($commit) {
132 return substr($commit, 0, 12);
135 private function buildCommitLink($hash) {
136 $commit_for_link = idx($this->commitsForLinks, $hash);
137 $commit_hash = self::formatCommit($hash);
138 if ($commit_for_link) {
139 $link = phutil_tag(
140 'a',
141 array(
142 'href' => $commit_for_link->getURI(),
144 $commit_hash);
145 } else {
146 $link = $commit_hash;
148 return $link;