Import.php 988 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 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. /**
  11. * Imports macros.
  12. *
  13. * <pre>
  14. * {% import 'forms.html' as forms %}
  15. * </pre>
  16. */
  17. class Twig_TokenParser_Import extends Twig_TokenParser
  18. {
  19. public function parse(Twig_Token $token)
  20. {
  21. $macro = $this->parser->getExpressionParser()->parseExpression();
  22. $this->parser->getStream()->expect('as');
  23. $var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine());
  24. $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
  25. $this->parser->addImportedSymbol('template', $var->getAttribute('name'));
  26. return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag());
  27. }
  28. public function getTag()
  29. {
  30. return 'import';
  31. }
  32. }