Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / lib / Twig / TokenParser / With.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
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 /**
13  * Creates a nested scope.
14  *
15  * @author Fabien Potencier <fabien@symfony.com>
16  *
17  * @final
18  */
19 class Twig_TokenParser_With extends Twig_TokenParser
20 {
21     public function parse(Twig_Token $token)
22     {
23         $stream = $this->parser->getStream();
24
25         $variables = null;
26         $only = false;
27         if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
28             $variables = $this->parser->getExpressionParser()->parseExpression();
29             $only = $stream->nextIf(Twig_Token::NAME_TYPE, 'only');
30         }
31
32         $stream->expect(Twig_Token::BLOCK_END_TYPE);
33
34         $body = $this->parser->subparse(array($this, 'decideWithEnd'), true);
35
36         $stream->expect(Twig_Token::BLOCK_END_TYPE);
37
38         return new Twig_Node_With($body, $variables, $only, $token->getLine(), $this->getTag());
39     }
40
41     public function decideWithEnd(Twig_Token $token)
42     {
43         return $token->test('endwith');
44     }
45
46     public function getTag()
47     {
48         return 'with';
49     }
50 }
51
52 class_alias('Twig_TokenParser_With', 'Twig\TokenParser\WithTokenParser', false);