Body.php 885B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. class Twig_Extensions_Grammar_Body extends Twig_Extensions_Grammar
  11. {
  12. protected $end;
  13. public function __construct($name, $end = null)
  14. {
  15. parent::__construct($name);
  16. $this->end = null === $end ? 'end'.$name : $end;
  17. }
  18. public function __toString()
  19. {
  20. return sprintf('<%s:body>', $this->name);
  21. }
  22. public function parse(Twig_Token $token)
  23. {
  24. $stream = $this->parser->getStream();
  25. $stream->expect(Twig_Token::BLOCK_END_TYPE);
  26. return $this->parser->subparse(array($this, 'decideBlockEnd'), true);
  27. }
  28. public function decideBlockEnd($token)
  29. {
  30. return $token->test($this->end);
  31. }
  32. }