forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhutilSafeHTML.php
44 lines (33 loc) · 955 Bytes
/
PhutilSafeHTML.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
final class PhutilSafeHTML extends Phobject {
private $content;
public function __construct($content) {
$this->content = (string)$content;
}
public function __toString() {
return $this->content;
}
public function getHTMLContent() {
return $this->content;
}
public function appendHTML($html /* , ... */) {
foreach (func_get_args() as $html) {
$this->content .= phutil_escape_html($html);
}
return $this;
}
public static function applyFunction($function, $string /* , ... */) {
$args = func_get_args();
array_shift($args);
$args = array_map('phutil_escape_html', $args);
return new PhutilSafeHTML(call_user_func_array($function, $args));
}
// Requires http://pecl.php.net/operator.
public function __concat($html) {
$clone = clone $this;
return $clone->appendHTML($html);
}
public function __assign_concat($html) {
return $this->appendHTML($html);
}
}