@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HeraldObjectTranscript extends Phobject {
4
5 protected $phid;
6 protected $type;
7 protected $name;
8 protected $fields;
9 protected $appliedTransactionPHIDs;
10 protected $profile;
11
12 public function setPHID($phid) {
13 $this->phid = $phid;
14 return $this;
15 }
16
17 public function getPHID() {
18 return $this->phid;
19 }
20
21 public function setType($type) {
22 $this->type = $type;
23 return $this;
24 }
25
26 public function getType() {
27 return $this->type;
28 }
29
30 public function setName($name) {
31 $this->name = $name;
32 return $this;
33 }
34
35 public function getName() {
36 return $this->name;
37 }
38
39 public function setFields(array $fields) {
40 foreach ($fields as $key => $value) {
41 $fields[$key] = self::truncateValue($value, 4096);
42 }
43
44 $this->fields = $fields;
45 return $this;
46 }
47
48 public function getFields() {
49 return $this->fields;
50 }
51
52 public function setProfile(array $profile) {
53 $this->profile = $profile;
54 return $this;
55 }
56
57 public function getProfile() {
58 return $this->profile;
59 }
60
61 public function setAppliedTransactionPHIDs($phids) {
62 $this->appliedTransactionPHIDs = $phids;
63 return $this;
64 }
65
66 public function getAppliedTransactionPHIDs() {
67 return $this->appliedTransactionPHIDs;
68 }
69
70 private static function truncateValue($value, $length) {
71 if (is_string($value)) {
72 if (strlen($value) <= $length) {
73 return $value;
74 } else {
75 // NOTE: PhutilUTF8StringTruncator has huge runtime for giant strings.
76 return phutil_utf8ize(substr($value, 0, $length)."\n<...>");
77 }
78 } else if (is_array($value)) {
79 foreach ($value as $key => $v) {
80 if ($length <= 0) {
81 $value['<...>'] = '<...>';
82 unset($value[$key]);
83 } else {
84 $v = self::truncateValue($v, $length);
85 $length -= strlen($v);
86 $value[$key] = $v;
87 }
88 }
89 return $value;
90 } else {
91 return $value;
92 }
93 }
94
95}