vendor/twig/twig/src/TokenParser/ExtendsTokenParser.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  * (c) 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. namespace Twig\TokenParser;
  12. use Twig\Error\SyntaxError;
  13. use Twig\Node\Node;
  14. use Twig\Token;
  15. /**
  16.  * Extends a template by another one.
  17.  *
  18.  *  {% extends "base.html" %}
  19.  *
  20.  * @internal
  21.  */
  22. final class ExtendsTokenParser extends AbstractTokenParser
  23. {
  24.     public function parse(Token $token): Node
  25.     {
  26.         $stream $this->parser->getStream();
  27.         if ($this->parser->peekBlockStack()) {
  28.             throw new SyntaxError('Cannot use "extend" in a block.'$token->getLine(), $stream->getSourceContext());
  29.         } elseif (!$this->parser->isMainScope()) {
  30.             throw new SyntaxError('Cannot use "extend" in a macro.'$token->getLine(), $stream->getSourceContext());
  31.         }
  32.         if (null !== $this->parser->getParent()) {
  33.             throw new SyntaxError('Multiple extends tags are forbidden.'$token->getLine(), $stream->getSourceContext());
  34.         }
  35.         $this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
  36.         $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  37.         return new Node();
  38.     }
  39.     public function getTag(): string
  40.     {
  41.         return 'extends';
  42.     }
  43. }