FormThemeTokenParser.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\Twig\TokenParser;
  11. use Symfony\Bridge\Twig\Node\FormThemeNode;
  12. /**
  13. * Token Parser for the 'form_theme' tag.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class FormThemeTokenParser extends \Twig_TokenParser
  18. {
  19. /**
  20. * Parses a token and returns a node.
  21. *
  22. * @param \Twig_Token $token A Twig_Token instance
  23. *
  24. * @return \Twig_NodeInterface A Twig_NodeInterface instance
  25. */
  26. public function parse(\Twig_Token $token)
  27. {
  28. $lineno = $token->getLine();
  29. $stream = $this->parser->getStream();
  30. $form = $this->parser->getExpressionParser()->parseExpression();
  31. if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
  32. $this->parser->getStream()->next();
  33. $resources = $this->parser->getExpressionParser()->parseExpression();
  34. } else {
  35. $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
  36. do {
  37. $resources->addElement($this->parser->getExpressionParser()->parseExpression());
  38. } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
  39. }
  40. $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  41. return new FormThemeNode($form, $resources, $lineno, $this->getTag());
  42. }
  43. /**
  44. * Gets the tag name associated with this token parser.
  45. *
  46. * @return string The tag name
  47. */
  48. public function getTag()
  49. {
  50. return 'form_theme';
  51. }
  52. }