Project

General

Profile

1
<?php
2

    
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 * (c) 2009 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

    
13
/**
14
 * Extends a template by another one.
15
 *
16
 * <pre>
17
 *  {% extends "base.html" %}
18
 * </pre>
19
 */
20
class Twig_TokenParser_Extends extends Twig_TokenParser
21
{
22
    public function parse(Twig_Token $token)
23
    {
24
        if (!$this->parser->isMainScope()) {
25
            throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $this->parser->getFilename());
26
        }
27

    
28
        if (null !== $this->parser->getParent()) {
29
            throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $this->parser->getFilename());
30
        }
31
        $this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
32

    
33
        $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
34
    }
35

    
36
    public function getTag()
37
    {
38
        return 'extends';
39
    }
40
}
(5-5/17)