| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of Twig. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier |
| 7 |
* (c) Armin Ronacher |
| 8 |
* |
| 9 |
* For the full copyright and license information, please view the LICENSE |
| 10 |
* file that was distributed with this source code. |
| 11 |
*/ |
| 12 |
namespace ElementorDeps\Twig\TokenParser; |
| 13 |
|
| 14 |
use ElementorDeps\Twig\Error\SyntaxError; |
| 15 |
use ElementorDeps\Twig\Node\Node; |
| 16 |
use ElementorDeps\Twig\Token; |
| 17 |
/** |
| 18 |
* Extends a template by another one. |
| 19 |
* |
| 20 |
* {% extends "base.html" %} |
| 21 |
* |
| 22 |
* @internal |
| 23 |
*/ |
| 24 |
final class ExtendsTokenParser extends AbstractTokenParser |
| 25 |
{ |
| 26 |
public function parse(Token $token) : Node |
| 27 |
{ |
| 28 |
$stream = $this->parser->getStream(); |
| 29 |
if ($this->parser->peekBlockStack()) { |
| 30 |
throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext()); |
| 31 |
} elseif (!$this->parser->isMainScope()) { |
| 32 |
throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext()); |
| 33 |
} |
| 34 |
if (null !== $this->parser->getParent()) { |
| 35 |
throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); |
| 36 |
} |
| 37 |
$this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); |
| 38 |
$stream->expect( |
| 39 |
/* Token::BLOCK_END_TYPE */ |
| 40 |
3 |
| 41 |
); |
| 42 |
return new Node(); |
| 43 |
} |
| 44 |
public function getTag() : string |
| 45 |
{ |
| 46 |
return 'extends'; |
| 47 |
} |
| 48 |
} |
| 49 |
|