Markup.php 788B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2010 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Marks a content as safe.
  12. *
  13. * @package twig
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class Twig_Markup implements Countable
  17. {
  18. protected $content;
  19. protected $charset;
  20. public function __construct($content, $charset)
  21. {
  22. $this->content = (string) $content;
  23. $this->charset = $charset;
  24. }
  25. public function __toString()
  26. {
  27. return $this->content;
  28. }
  29. public function count()
  30. {
  31. return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content);
  32. }
  33. }