2024-06-20 14:10:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Twig.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Twig;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks a content as safe.
|
|
|
|
*
|
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
|
*/
|
2025-01-13 09:56:01 +00:00
|
|
|
class Markup implements \Countable, \JsonSerializable, \Stringable
|
2024-06-20 14:10:42 +00:00
|
|
|
{
|
|
|
|
private $content;
|
2025-01-13 09:56:01 +00:00
|
|
|
private ?string $charset;
|
2024-06-20 14:10:42 +00:00
|
|
|
|
|
|
|
public function __construct($content, $charset)
|
|
|
|
{
|
|
|
|
$this->content = (string) $content;
|
|
|
|
$this->charset = $charset;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
2025-01-13 09:56:01 +00:00
|
|
|
public function getCharset(): string
|
|
|
|
{
|
|
|
|
return $this->charset;
|
|
|
|
}
|
|
|
|
|
2024-06-20 14:10:42 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
#[\ReturnTypeWillChange]
|
|
|
|
public function count()
|
|
|
|
{
|
|
|
|
return mb_strlen($this->content, $this->charset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
#[\ReturnTypeWillChange]
|
|
|
|
public function jsonSerialize()
|
|
|
|
{
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
}
|