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 13namespace Twig\TokenParser; 14 15use Twig\Error\SyntaxError; 16use Twig\Node\Node; 17use Twig\Token; 18 19/** 20 * Extends a template by another one. 21 * 22 * {% extends "base.html" %} 23 */ 24final class ExtendsTokenParser extends AbstractTokenParser 25{ 26 public function parse(Token $token) 27 { 28 $stream = $this->parser->getStream(); 29 30 if ($this->parser->peekBlockStack()) { 31 throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext()); 32 } elseif (!$this->parser->isMainScope()) { 33 throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext()); 34 } 35 36 if (null !== $this->parser->getParent()) { 37 throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); 38 } 39 $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); 40 41 $stream->expect(Token::BLOCK_END_TYPE); 42 43 return new Node(); 44 } 45 46 public function getTag() 47 { 48 return 'extends'; 49 } 50} 51 52class_alias('Twig\TokenParser\ExtendsTokenParser', 'Twig_TokenParser_Extends'); 53