Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Component / Render / HtmlEscapedText.php
1 <?php
2
3 namespace Drupal\Component\Render;
4
5 use Drupal\Component\Utility\Html;
6
7 /**
8  * Escapes HTML syntax characters to HTML entities for display in markup.
9  *
10  * This class can be used to provide theme engine-like late escaping
11  * functionality.
12  *
13  * @ingroup sanitization
14  */
15 class HtmlEscapedText implements MarkupInterface, \Countable {
16
17   /**
18    * The string to escape.
19    *
20    * @var string
21    */
22   protected $string;
23
24   /**
25    * Constructs an HtmlEscapedText object.
26    *
27    * @param $string
28    *   The string to escape. This value will be cast to a string.
29    */
30   public function __construct($string) {
31     $this->string = (string) $string;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function __toString() {
38     return Html::escape($this->string);
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function count() {
45     return mb_strlen($this->string);
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function jsonSerialize() {
52     return $this->__toString();
53   }
54
55 }