Security update for Core, with self-updated composer
[yaffs-website] / vendor / twig / twig / lib / Twig / TokenParser / Macro.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  * Defines a macro.
14  *
15  * <pre>
16  * {% macro input(name, value, type, size) %}
17  *    <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
18  * {% endmacro %}
19  * </pre>
20  *
21  * @final
22  */
23 class Twig_TokenParser_Macro extends Twig_TokenParser
24 {
25     public function parse(Twig_Token $token)
26     {
27         $lineno = $token->getLine();
28         $stream = $this->parser->getStream();
29         $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
30
31         $arguments = $this->parser->getExpressionParser()->parseArguments(true, true);
32
33         $stream->expect(Twig_Token::BLOCK_END_TYPE);
34         $this->parser->pushLocalScope();
35         $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
36         if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
37             $value = $token->getValue();
38
39             if ($value != $name) {
40                 throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
41             }
42         }
43         $this->parser->popLocalScope();
44         $stream->expect(Twig_Token::BLOCK_END_TYPE);
45
46         $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body(array($body)), $arguments, $lineno, $this->getTag()));
47     }
48
49     public function decideBlockEnd(Twig_Token $token)
50     {
51         return $token->test('endmacro');
52     }
53
54     public function getTag()
55     {
56         return 'macro';
57     }
58 }
59
60 class_alias('Twig_TokenParser_Macro', 'Twig\TokenParser\MacroTokenParser', false);