Extends.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. * (c) 2009 Armin Ronacher
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. /**
  12. * Extends a template by another one.
  13. *
  14. * <pre>
  15. * {% extends "base.html" %}
  16. * </pre>
  17. */
  18. class Twig_TokenParser_Extends extends Twig_TokenParser
  19. {
  20. /**
  21. * Parses a token and returns a node.
  22. *
  23. * @param Twig_Token $token A Twig_Token instance
  24. *
  25. * @return Twig_NodeInterface A Twig_NodeInterface instance
  26. */
  27. public function parse(Twig_Token $token)
  28. {
  29. if (null !== $this->parser->getParent()) {
  30. throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine());
  31. }
  32. $this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
  33. $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
  34. return null;
  35. }
  36. /**
  37. * Gets the tag name associated with this token parser.
  38. *
  39. * @param string The tag name
  40. */
  41. public function getTag()
  42. {
  43. return 'extends';
  44. }
  45. }