Security update for Core, with self-updated composer
[yaffs-website] / vendor / twig / twig / lib / Twig / TokenParser / Embed.php
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
12 /**
13  * Embeds a template.
14  *
15  * @final
16  */
17 class Twig_TokenParser_Embed extends Twig_TokenParser_Include
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(
36             new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()),
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
51         $stream->expect(Twig_Token::BLOCK_END_TYPE);
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);