blob: 1788acc4f73f8c89340909fbb5abef8d38f85019 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Twig;
13
14/**
15 * Marks a content as safe.
16 *
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19class Markup implements \Countable, \JsonSerializable
20{
21 private $content;
22 private $charset;
23
24 public function __construct($content, $charset)
25 {
26 $this->content = (string) $content;
27 $this->charset = $charset;
28 }
29
30 public function __toString()
31 {
32 return $this->content;
33 }
34
35 /**
36 * @return int
37 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010038 #[\ReturnTypeWillChange]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010039 public function count()
40 {
41 return mb_strlen($this->content, $this->charset);
42 }
43
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010044 /**
45 * @return mixed
46 */
47 #[\ReturnTypeWillChange]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010048 public function jsonSerialize()
49 {
50 return $this->content;
51 }
52}