vendor/symfony/twig-bridge/TokenParser/FormThemeTokenParser.php line 51

  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. use Twig\Node\Expression\ArrayExpression;
  13. use Twig\Node\Node;
  14. use Twig\Token;
  15. use Twig\TokenParser\AbstractTokenParser;
  16. /**
  17.  * Token Parser for the 'form_theme' tag.
  18.  *
  19.  * @author Fabien Potencier <fabien@symfony.com>
  20.  */
  21. final class FormThemeTokenParser extends AbstractTokenParser
  22. {
  23.     public function parse(Token $token): Node
  24.     {
  25.         $lineno $token->getLine();
  26.         $stream $this->parser->getStream();
  27.         $form $this->parser->getExpressionParser()->parseExpression();
  28.         $only false;
  29.         if ($this->parser->getStream()->test(Token::NAME_TYPE'with')) {
  30.             $this->parser->getStream()->next();
  31.             $resources $this->parser->getExpressionParser()->parseExpression();
  32.             if ($this->parser->getStream()->nextIf(Token::NAME_TYPE'only')) {
  33.                 $only true;
  34.             }
  35.         } else {
  36.             $resources = new ArrayExpression([], $stream->getCurrent()->getLine());
  37.             do {
  38.                 $resources->addElement($this->parser->getExpressionParser()->parseExpression());
  39.             } while (!$stream->test(Token::BLOCK_END_TYPE));
  40.         }
  41.         $stream->expect(Token::BLOCK_END_TYPE);
  42.         return new FormThemeNode($form$resources$lineno$this->getTag(), $only);
  43.     }
  44.     public function getTag(): string
  45.     {
  46.         return 'form_theme';
  47.     }
  48. }