vendor/twig/twig/src/TokenParser/ImportTokenParser.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  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 Twig\TokenParser;
  11. use Twig\Node\Expression\AssignNameExpression;
  12. use Twig\Node\ImportNode;
  13. use Twig\Node\Node;
  14. use Twig\Token;
  15. /**
  16.  * Imports macros.
  17.  *
  18.  *   {% import 'forms.html' as forms %}
  19.  *
  20.  * @internal
  21.  */
  22. final class ImportTokenParser extends AbstractTokenParser
  23. {
  24.     public function parse(Token $token): Node
  25.     {
  26.         $macro $this->parser->getExpressionParser()->parseExpression();
  27.         $this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5'as');
  28.         $var = new AssignNameExpression($this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5)->getValue(), $token->getLine());
  29.         $this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3);
  30.         $this->parser->addImportedSymbol('template'$var->getAttribute('name'));
  31.         return new ImportNode($macro$var$token->getLine(), $this->getTag(), $this->parser->isMainScope());
  32.     }
  33.     public function getTag(): string
  34.     {
  35.         return 'import';
  36.     }
  37. }