Rev | Line | |
---|
[345] | 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 | class Twig_TokenParser_Include extends Twig_TokenParser |
---|
| 13 | { |
---|
| 14 | /** |
---|
| 15 | * Parses a token and returns a node. |
---|
| 16 | * |
---|
| 17 | * @param Twig_Token $token A Twig_Token instance |
---|
| 18 | * |
---|
| 19 | * @return Twig_NodeInterface A Twig_NodeInterface instance |
---|
| 20 | */ |
---|
| 21 | public function parse(Twig_Token $token) |
---|
| 22 | { |
---|
| 23 | $expr = $this->parser->getExpressionParser()->parseExpression(); |
---|
| 24 | |
---|
| 25 | $variables = null; |
---|
| 26 | if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE, 'with')) { |
---|
| 27 | $this->parser->getStream()->next(); |
---|
| 28 | |
---|
| 29 | $variables = $this->parser->getExpressionParser()->parseExpression(); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | $only = false; |
---|
| 33 | if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE, 'only')) { |
---|
| 34 | $this->parser->getStream()->next(); |
---|
| 35 | |
---|
| 36 | $only = true; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); |
---|
| 40 | |
---|
| 41 | return new Twig_Node_Include($expr, $variables, $only, $token->getLine(), $this->getTag()); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Gets the tag name associated with this token parser. |
---|
| 46 | * |
---|
| 47 | * @param string The tag name |
---|
| 48 | */ |
---|
| 49 | public function getTag() |
---|
| 50 | { |
---|
| 51 | return 'include'; |
---|
| 52 | } |
---|
| 53 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.