1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Twig\TokenParser; 13 14use Twig\Node\Expression\AssignNameExpression; 15use Twig\Node\ImportNode; 16use Twig\Token; 17 18/** 19 * Imports macros. 20 * 21 * {% import 'forms.html' as forms %} 22 * 23 * @final 24 */ 25class ImportTokenParser extends AbstractTokenParser 26{ 27 public function parse(Token $token) 28 { 29 $macro = $this->parser->getExpressionParser()->parseExpression(); 30 $this->parser->getStream()->expect('as'); 31 $var = new AssignNameExpression($this->parser->getStream()->expect(Token::NAME_TYPE)->getValue(), $token->getLine()); 32 $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); 33 34 $this->parser->addImportedSymbol('template', $var->getAttribute('name')); 35 36 return new ImportNode($macro, $var, $token->getLine(), $this->getTag()); 37 } 38 39 public function getTag() 40 { 41 return 'import'; 42 } 43} 44 45class_alias('Twig\TokenParser\ImportTokenParser', 'Twig_TokenParser_Import'); 46