-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHtmlEscapedText.php
55 lines (46 loc) · 992 Bytes
/
HtmlEscapedText.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
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Drupal\Component\Render;
use Drupal\Component\Utility\Html;
/**
* Escapes HTML syntax characters to HTML entities for display in markup.
*
* This class can be used to provide theme engine-like late escaping
* functionality.
*
* @ingroup sanitization
*/
class HtmlEscapedText implements MarkupInterface, \Countable {
/**
* The string to escape.
*
* @var string
*/
protected $string;
/**
* Constructs an HtmlEscapedText object.
*
* @param string $string
* The string to escape. This value will be cast to a string.
*/
public function __construct($string) {
$this->string = (string) $string;
}
/**
* {@inheritdoc}
*/
public function __toString() {
return Html::escape($this->string);
}
/**
* {@inheritdoc}
*/
public function count(): int {
return mb_strlen($this->string);
}
/**
* {@inheritdoc}
*/
public function jsonSerialize(): string {
return $this->__toString();
}
}