@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 PhutilSafeHTML extends Phobject {
4
5 private $content;
6
7 public function __construct($content) {
8 $this->content = (string)$content;
9 }
10
11 public function __toString() {
12 return $this->content;
13 }
14
15 public function getHTMLContent() {
16 return $this->content;
17 }
18
19 public function appendHTML($html /* , ... */) {
20 foreach (func_get_args() as $html) {
21 $this->content .= phutil_escape_html($html);
22 }
23 return $this;
24 }
25
26 public static function applyFunction($function, $string /* , ... */) {
27 $args = func_get_args();
28 array_shift($args);
29 $args = array_map('phutil_escape_html', $args);
30 return new PhutilSafeHTML(call_user_func_array($function, $args));
31 }
32
33// Requires http://pecl.php.net/operator.
34
35 public function __concat($html) {
36 $clone = clone $this;
37 return $clone->appendHTML($html);
38 }
39
40 public function __assign_concat($html) {
41 return $this->appendHTML($html);
42 }
43
44}