class ImportTokenParser
Imports macros.
{% import 'forms.html' as forms %}
@internal
Hierarchy
- class \Twig\TokenParser\AbstractTokenParser implements \Twig\TokenParser\TokenParserInterface
- class \Twig\TokenParser\ImportTokenParser extends \Twig\TokenParser\AbstractTokenParser
Expanded class hierarchy of ImportTokenParser
1 file declares its use of ImportTokenParser
- CoreExtension.php in vendor/
twig/ twig/ src/ Extension/ CoreExtension.php
File
-
vendor/
twig/ twig/ src/ TokenParser/ ImportTokenParser.php, line 27
Namespace
Twig\TokenParserView source
final class ImportTokenParser extends AbstractTokenParser {
public function parse(Token $token) : Node {
$macro = $this->parser
->getExpressionParser()
->parseExpression();
$this->parser
->getStream()
->expect(Token::NAME_TYPE, 'as');
$name = $this->parser
->getStream()
->expect(Token::NAME_TYPE)
->getValue();
$var = new AssignTemplateVariable(new TemplateVariable($name, $token->getLine()), $this->parser
->isMainScope());
$this->parser
->getStream()
->expect(Token::BLOCK_END_TYPE);
$this->parser
->addImportedSymbol('template', $name);
return new ImportNode($macro, $var, $token->getLine());
}
public function getTag() : string {
return 'import';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
AbstractTokenParser::$parser | protected | property | ||
AbstractTokenParser::setParser | public | function | Sets the parser associated with this token parser. | Overrides TokenParserInterface::setParser |
ImportTokenParser::getTag | public | function | Gets the tag name associated with this token parser. | Overrides TokenParserInterface::getTag |
ImportTokenParser::parse | public | function | Parses a token and returns a node. | Overrides TokenParserInterface::parse |