Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Render/HtmlEscapedText.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Component\Render; | |
4 | |
5 use Drupal\Component\Utility\Html; | |
6 use Drupal\Component\Utility\Unicode; | |
7 | |
8 /** | |
9 * Escapes HTML syntax characters to HTML entities for display in markup. | |
10 * | |
11 * This class can be used to provide theme engine-like late escaping | |
12 * functionality. | |
13 * | |
14 * @ingroup sanitization | |
15 */ | |
16 class HtmlEscapedText implements MarkupInterface, \Countable { | |
17 | |
18 /** | |
19 * The string to escape. | |
20 * | |
21 * @var string | |
22 */ | |
23 protected $string; | |
24 | |
25 /** | |
26 * Constructs an HtmlEscapedText object. | |
27 * | |
28 * @param $string | |
29 * The string to escape. This value will be cast to a string. | |
30 */ | |
31 public function __construct($string) { | |
32 $this->string = (string) $string; | |
33 } | |
34 | |
35 /** | |
36 * {@inheritdoc} | |
37 */ | |
38 public function __toString() { | |
39 return Html::escape($this->string); | |
40 } | |
41 | |
42 /** | |
43 * {@inheritdoc} | |
44 */ | |
45 public function count() { | |
46 return Unicode::strlen($this->string); | |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 public function jsonSerialize() { | |
53 return $this->__toString(); | |
54 } | |
55 | |
56 } |