Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/data/DiffusionCommitRef.php
12241 views
1
<?php
2
3
final class DiffusionCommitRef extends Phobject {
4
5
private $message;
6
private $authorEpoch;
7
private $authorName;
8
private $authorEmail;
9
private $committerName;
10
private $committerEmail;
11
private $hashes = array();
12
13
public function newDictionary() {
14
$hashes = $this->getHashes();
15
$hashes = mpull($hashes, 'newDictionary');
16
$hashes = array_values($hashes);
17
18
return array(
19
'authorEpoch' => $this->authorEpoch,
20
'authorName' => $this->authorName,
21
'authorEmail' => $this->authorEmail,
22
'committerName' => $this->committerName,
23
'committerEmail' => $this->committerEmail,
24
'message' => $this->message,
25
'hashes' => $hashes,
26
);
27
}
28
29
public static function newFromDictionary(array $map) {
30
$hashes = idx($map, 'hashes', array());
31
foreach ($hashes as $key => $hash_map) {
32
$hashes[$key] = DiffusionCommitHash::newFromDictionary($hash_map);
33
}
34
$hashes = array_values($hashes);
35
36
$author_epoch = idx($map, 'authorEpoch');
37
$author_name = idx($map, 'authorName');
38
$author_email = idx($map, 'authorEmail');
39
$committer_name = idx($map, 'committerName');
40
$committer_email = idx($map, 'committerEmail');
41
$message = idx($map, 'message');
42
43
return id(new self())
44
->setAuthorEpoch($author_epoch)
45
->setAuthorName($author_name)
46
->setAuthorEmail($author_email)
47
->setCommitterName($committer_name)
48
->setCommitterEmail($committer_email)
49
->setMessage($message)
50
->setHashes($hashes);
51
}
52
53
public function setHashes(array $hashes) {
54
assert_instances_of($hashes, 'DiffusionCommitHash');
55
$this->hashes = $hashes;
56
return $this;
57
}
58
59
public function getHashes() {
60
return $this->hashes;
61
}
62
63
public function setAuthorEpoch($author_epoch) {
64
$this->authorEpoch = $author_epoch;
65
return $this;
66
}
67
68
public function getAuthorEpoch() {
69
return $this->authorEpoch;
70
}
71
72
public function setCommitterEmail($committer_email) {
73
$this->committerEmail = $committer_email;
74
return $this;
75
}
76
77
public function getCommitterEmail() {
78
return $this->committerEmail;
79
}
80
81
82
public function setCommitterName($committer_name) {
83
$this->committerName = $committer_name;
84
return $this;
85
}
86
87
public function getCommitterName() {
88
return $this->committerName;
89
}
90
91
92
public function setAuthorEmail($author_email) {
93
$this->authorEmail = $author_email;
94
return $this;
95
}
96
97
public function getAuthorEmail() {
98
return $this->authorEmail;
99
}
100
101
102
public function setAuthorName($author_name) {
103
$this->authorName = $author_name;
104
return $this;
105
}
106
107
public function getAuthorName() {
108
return $this->authorName;
109
}
110
111
public function setMessage($message) {
112
$this->message = $message;
113
return $this;
114
}
115
116
public function getMessage() {
117
return $this->message;
118
}
119
120
public function getAuthor() {
121
return $this->formatUser($this->authorName, $this->authorEmail);
122
}
123
124
public function getCommitter() {
125
return $this->formatUser($this->committerName, $this->committerEmail);
126
}
127
128
public function getSummary() {
129
return PhabricatorRepositoryCommitData::summarizeCommitMessage(
130
$this->getMessage());
131
}
132
133
private function formatUser($name, $email) {
134
if ($name === null) {
135
$name = '';
136
}
137
if ($email === null) {
138
$email = '';
139
}
140
141
if (strlen($name) && strlen($email)) {
142
return "{$name} <{$email}>";
143
} else if (strlen($email)) {
144
return $email;
145
} else if (strlen($name)) {
146
return $name;
147
} else {
148
return null;
149
}
150
}
151
152
}
153
154