Mercurial > hg > isophonics-drupal-site
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/lib/Drupal/Component/Render/HtmlEscapedText.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,56 @@ +<?php + +namespace Drupal\Component\Render; + +use Drupal\Component\Utility\Html; +use Drupal\Component\Utility\Unicode; + +/** + * 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 + * 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() { + return Unicode::strlen($this->string); + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() { + return $this->__toString(); + } + +}