Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / data / DiffusionCommitRef.php
blob1d90a37d07b5f85184bcb6b7e7a0ba305cdf713e
1 <?php
3 final class DiffusionCommitRef extends Phobject {
5 private $message;
6 private $authorEpoch;
7 private $authorName;
8 private $authorEmail;
9 private $committerName;
10 private $committerEmail;
11 private $hashes = array();
13 public function newDictionary() {
14 $hashes = $this->getHashes();
15 $hashes = mpull($hashes, 'newDictionary');
16 $hashes = array_values($hashes);
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,
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);
34 $hashes = array_values($hashes);
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');
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);
53 public function setHashes(array $hashes) {
54 assert_instances_of($hashes, 'DiffusionCommitHash');
55 $this->hashes = $hashes;
56 return $this;
59 public function getHashes() {
60 return $this->hashes;
63 public function setAuthorEpoch($author_epoch) {
64 $this->authorEpoch = $author_epoch;
65 return $this;
68 public function getAuthorEpoch() {
69 return $this->authorEpoch;
72 public function setCommitterEmail($committer_email) {
73 $this->committerEmail = $committer_email;
74 return $this;
77 public function getCommitterEmail() {
78 return $this->committerEmail;
82 public function setCommitterName($committer_name) {
83 $this->committerName = $committer_name;
84 return $this;
87 public function getCommitterName() {
88 return $this->committerName;
92 public function setAuthorEmail($author_email) {
93 $this->authorEmail = $author_email;
94 return $this;
97 public function getAuthorEmail() {
98 return $this->authorEmail;
102 public function setAuthorName($author_name) {
103 $this->authorName = $author_name;
104 return $this;
107 public function getAuthorName() {
108 return $this->authorName;
111 public function setMessage($message) {
112 $this->message = $message;
113 return $this;
116 public function getMessage() {
117 return $this->message;
120 public function getAuthor() {
121 return $this->formatUser($this->authorName, $this->authorEmail);
124 public function getCommitter() {
125 return $this->formatUser($this->committerName, $this->committerEmail);
128 public function getSummary() {
129 return PhabricatorRepositoryCommitData::summarizeCommitMessage(
130 $this->getMessage());
133 private function formatUser($name, $email) {
134 if ($name === null) {
135 $name = '';
137 if ($email === null) {
138 $email = '';
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;