2011-03-22 21:22:40 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-14 00:21:04 +01:00
|
|
|
final class HeraldObjectTranscript {
|
2011-03-22 21:22:40 +01:00
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
protected $phid;
|
2011-03-22 21:22:40 +01:00
|
|
|
protected $type;
|
|
|
|
protected $name;
|
|
|
|
protected $fields;
|
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
public function setPHID($phid) {
|
|
|
|
$this->phid = $phid;
|
2011-03-22 21:22:40 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-03-25 05:32:26 +01:00
|
|
|
public function getPHID() {
|
|
|
|
return $this->phid;
|
2011-03-22 21:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setType($type) {
|
|
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getType() {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFields(array $fields) {
|
2013-12-18 20:59:53 +01:00
|
|
|
foreach ($fields as $key => $value) {
|
|
|
|
$fields[$key] = self::truncateValue($value, 4096);
|
|
|
|
}
|
|
|
|
|
2011-03-22 21:22:40 +01:00
|
|
|
$this->fields = $fields;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFields() {
|
|
|
|
return $this->fields;
|
|
|
|
}
|
2013-12-18 20:59:53 +01:00
|
|
|
|
|
|
|
private static function truncateValue($value, $length) {
|
|
|
|
if (is_string($value)) {
|
|
|
|
if (strlen($value) <= $length) {
|
|
|
|
return $value;
|
|
|
|
} else {
|
2014-08-30 00:15:13 +02:00
|
|
|
// NOTE: PhutilUTF8StringTruncator has huge runtime for giant strings.
|
2013-12-18 20:59:53 +01:00
|
|
|
return phutil_utf8ize(substr($value, 0, $length)."\n<...>");
|
|
|
|
}
|
|
|
|
} else if (is_array($value)) {
|
|
|
|
foreach ($value as $key => $v) {
|
|
|
|
if ($length <= 0) {
|
|
|
|
$value['<...>'] = '<...>';
|
|
|
|
unset($value[$key]);
|
|
|
|
} else {
|
|
|
|
$v = self::truncateValue($v, $length);
|
|
|
|
$length -= strlen($v);
|
|
|
|
$value[$key] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
} else {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-22 21:22:40 +01:00
|
|
|
}
|