ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Embed.php
Go to the documentation of this file.
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 
18 {
19  public function parse(Twig_Token $token)
20  {
21  $stream = $this->parser->getStream();
22 
23  $parent = $this->parser->getExpressionParser()->parseExpression();
24 
25  list($variables, $only, $ignoreMissing) = $this->parseArguments();
26 
27  $parentToken = $fakeParentToken = new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine());
28  if ($parent instanceof Twig_Node_Expression_Constant) {
29  $parentToken = new Twig_Token(Twig_Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine());
30  } elseif ($parent instanceof Twig_Node_Expression_Name) {
31  $parentToken = new Twig_Token(Twig_Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine());
32  }
33 
34  // inject a fake parent to make the parent() function work
35  $stream->injectTokens(array(
37  new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()),
38  $parentToken,
39  new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()),
40  ));
41 
42  $module = $this->parser->parse($stream, array($this, 'decideBlockEnd'), true);
43 
44  // override the parent with the correct one
45  if ($fakeParentToken === $parentToken) {
46  $module->setNode('parent', $parent);
47  }
48 
49  $this->parser->embedTemplate($module);
50 
52 
53  return new Twig_Node_Embed($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
54  }
55 
56  public function decideBlockEnd(Twig_Token $token)
57  {
58  return $token->test('endembed');
59  }
60 
61  public function getTag()
62  {
63  return 'embed';
64  }
65 }
66 
67 class_alias('Twig_TokenParser_Embed', 'Twig\TokenParser\EmbedTokenParser', false);
Includes a template.
Definition: Include.php:22
getTag()
Gets the tag name associated with this token parser.
Definition: Embed.php:61
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Embed.php:19
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
Embeds a template.
Definition: Embed.php:17
$stream
PHP stream implementation.
decideBlockEnd(Twig_Token $token)
Definition: Embed.php:56
if($modEnd===false) $module
Definition: module.php:59
const STRING_TYPE
Definition: Token.php:34
const BLOCK_START_TYPE
Definition: Token.php:28
Represents an embed node.
Definition: Embed.php:17
getLine()
Definition: Token.php:87
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30