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

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\Token;
  14. /**
  15. * Imports macros.
  16. *
  17. * {% import 'forms.html' as forms %}
  18. */
  19. final class ImportTokenParser extends AbstractTokenParser
  20. {
  21. public function parse(Token $token)
  22. {
  23. $macro = $this->parser->getExpressionParser()->parseExpression();
  24. $this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5, 'as');
  25. $var = new AssignNameExpression($this->parser->getStream()->expect(/* Token::NAME_TYPE */ 5)->getValue(), $token->getLine());
  26. $this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3);
  27. $this->parser->addImportedSymbol('template', $var->getAttribute('name'));
  28. return new ImportNode($macro, $var, $token->getLine(), $this->getTag(), $this->parser->isMainScope());
  29. }
  30. public function getTag()
  31. {
  32. return 'import';
  33. }
  34. }
  35. class_alias('Twig\TokenParser\ImportTokenParser', 'Twig_TokenParser_Import');