*/ class Markup implements \Countable, \JsonSerializable, \Stringable { private $content; private ?string $charset; /** * @param string[] $safeStrategies The escaping strategies the content is safe for, `['all']` for all of them */ public function __construct( $content, $charset, private array $safeStrategies = ['all'], ) { $this->content = (string) $content; $this->charset = $charset; } public function __toString(): string { return $this->content; } public function getCharset(): string { return $this->charset; } /** * @internal */ public function withContent(string $content): self { $markup = clone $this; $markup->content = $content; return $markup; } public function isSafeFor(string $strategy): bool { foreach ($this->safeStrategies as $declared) { if ('all' === $declared || $strategy === $declared || \in_array($strategy, EscaperRuntime::IMPLIED_STRATEGIES[$declared] ?? [], true)) { return true; } } return false; } /** * @return int */ #[\ReturnTypeWillChange] public function count() { return mb_strlen($this->content, $this->charset); } /** * @return mixed */ #[\ReturnTypeWillChange] public function jsonSerialize() { return $this->content; } }