Markup.php 764 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. * @author Fabien Potencier <fabien@symfony.com>
  14. */
  15. class Twig_Markup implements Countable
  16. {
  17. protected $content;
  18. protected $charset;
  19. public function __construct($content, $charset)
  20. {
  21. $this->content = (string) $content;
  22. $this->charset = $charset;
  23. }
  24. public function __toString()
  25. {
  26. return $this->content;
  27. }
  28. public function count()
  29. {
  30. return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content);
  31. }
  32. }