3 namespace Drupal\Component\Render;
6 * Implements MarkupInterface and Countable for rendered objects.
8 * @see \Drupal\Component\Render\MarkupInterface
20 * Creates a Markup object if necessary.
22 * If $string is equal to a blank string then it is not necessary to create a
23 * Markup object. If $string is an object that implements MarkupInterface it
24 * is returned unchanged.
26 * @param mixed $string
27 * The string to mark as safe. This value will be cast to a string.
29 * @return string|\Drupal\Component\Render\MarkupInterface
32 public static function create($string) {
33 if ($string instanceof MarkupInterface) {
36 $string = (string) $string;
40 $safe_string = new static();
41 $safe_string->string = $string;
46 * Returns the string version of the Markup object.
49 * The safe string content.
51 public function __toString() {
56 * Returns the string length.
59 * The length of the string.
61 public function count() {
62 return mb_strlen($this->string);
66 * Returns a representation of the object for use in JSON serialization.
69 * The safe string content.
71 public function jsonSerialize() {
72 return $this->__toString();