class EmbedTokenParser
Embeds a template.
@internal
Hierarchy
- class \Twig\TokenParser\AbstractTokenParser implements \Twig\TokenParser\TokenParserInterface
- class \Twig\TokenParser\IncludeTokenParser extends \Twig\TokenParser\AbstractTokenParser
- class \Twig\TokenParser\EmbedTokenParser extends \Twig\TokenParser\IncludeTokenParser
- class \Twig\TokenParser\IncludeTokenParser extends \Twig\TokenParser\AbstractTokenParser
Expanded class hierarchy of EmbedTokenParser
1 file declares its use of EmbedTokenParser
- CoreExtension.php in vendor/
twig/ twig/ src/ Extension/ CoreExtension.php
File
-
vendor/
twig/ twig/ src/ TokenParser/ EmbedTokenParser.php, line 25
Namespace
Twig\TokenParserView source
final class EmbedTokenParser extends IncludeTokenParser {
public function parse(Token $token) : Node {
$stream = $this->parser
->getStream();
$parent = $this->parser
->getExpressionParser()
->parseExpression();
[
$variables,
$only,
$ignoreMissing,
] = $this->parseArguments();
$parentToken = $fakeParentToken = new Token(Token::STRING_TYPE, '__parent__', $token->getLine());
if ($parent instanceof ConstantExpression) {
$parentToken = new Token(Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine());
}
elseif ($parent instanceof NameExpression) {
$parentToken = new Token(Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine());
}
// inject a fake parent to make the parent() function work
$stream->injectTokens([
new Token(Token::BLOCK_START_TYPE, '', $token->getLine()),
new Token(Token::NAME_TYPE, 'extends', $token->getLine()),
$parentToken,
new Token(Token::BLOCK_END_TYPE, '', $token->getLine()),
]);
$module = $this->parser
->parse($stream, [
$this,
'decideBlockEnd',
], true);
// override the parent with the correct one
if ($fakeParentToken === $parentToken) {
$module->setNode('parent', $parent);
}
$this->parser
->embedTemplate($module);
$stream->expect(Token::BLOCK_END_TYPE);
return new EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine());
}
public function decideBlockEnd(Token $token) : bool {
return $token->test('endembed');
}
public function getTag() : string {
return 'embed';
}
}
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 |
EmbedTokenParser::decideBlockEnd | public | function | ||
EmbedTokenParser::getTag | public | function | Gets the tag name associated with this token parser. | Overrides IncludeTokenParser::getTag |
EmbedTokenParser::parse | public | function | Parses a token and returns a node. | Overrides IncludeTokenParser::parse |
IncludeTokenParser::parseArguments | protected | function |