]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | /* | |
4 | * This file is part of the Symfony package. | |
5 | * | |
6 | * (c) Fabien Potencier <fabien@symfony.com> | |
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 | namespace Symfony\Bridge\Twig\TokenParser; | |
13 | ||
14 | use Symfony\Bridge\Twig\Node\FormThemeNode; | |
15 | ||
16 | /** | |
17 | * Token Parser for the 'form_theme' tag. | |
18 | * | |
19 | * @author Fabien Potencier <fabien@symfony.com> | |
20 | */ | |
21 | class FormThemeTokenParser extends \Twig_TokenParser | |
22 | { | |
23 | /** | |
24 | * Parses a token and returns a node. | |
25 | * | |
26 | * @param \Twig_Token $token A Twig_Token instance | |
27 | * | |
28 | * @return \Twig_NodeInterface A Twig_NodeInterface instance | |
29 | */ | |
30 | public function parse(\Twig_Token $token) | |
31 | { | |
32 | $lineno = $token->getLine(); | |
33 | $stream = $this->parser->getStream(); | |
34 | ||
35 | $form = $this->parser->getExpressionParser()->parseExpression(); | |
36 | ||
37 | if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) { | |
38 | $this->parser->getStream()->next(); | |
39 | $resources = $this->parser->getExpressionParser()->parseExpression(); | |
40 | } else { | |
41 | $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine()); | |
42 | do { | |
43 | $resources->addElement($this->parser->getExpressionParser()->parseExpression()); | |
44 | } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)); | |
45 | } | |
46 | ||
47 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); | |
48 | ||
49 | return new FormThemeNode($form, $resources, $lineno, $this->getTag()); | |
50 | } | |
51 | ||
52 | /** | |
53 | * Gets the tag name associated with this token parser. | |
54 | * | |
55 | * @return string The tag name | |
56 | */ | |
57 | public function getTag() | |
58 | { | |
59 | return 'form_theme'; | |
60 | } | |
61 | } |