3 namespace Drupal\Component\Render;
5 use Drupal\Component\Utility\Unicode;
8 * Implements MarkupInterface and Countable for rendered objects.
10 * @see \Drupal\Component\Render\MarkupInterface
22 * Creates a Markup object if necessary.
24 * If $string is equal to a blank string then it is not necessary to create a
25 * Markup object. If $string is an object that implements MarkupInterface it
26 * is returned unchanged.
28 * @param mixed $string
29 * The string to mark as safe. This value will be cast to a string.
31 * @return string|\Drupal\Component\Render\MarkupInterface
34 public static function create($string) {
35 if ($string instanceof MarkupInterface) {
38 $string = (string) $string;
42 $safe_string = new static();
43 $safe_string->string = $string;
48 * Returns the string version of the Markup object.
51 * The safe string content.
53 public function __toString() {
58 * Returns the string length.
61 * The length of the string.
63 public function count() {
64 return Unicode::strlen($this->string);
68 * Returns a representation of the object for use in JSON serialization.
71 * The safe string content.
73 public function jsonSerialize() {
74 return $this->__toString();