ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Macro.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
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
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();
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
60class_alias('Twig_TokenParser_Macro', 'Twig\TokenParser\MacroTokenParser', false);
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:19
Represents a body node.
Definition: Body.php:18
Represents a macro node.
Definition: Macro.php:18
Defines a macro.
Definition: Macro.php:24
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Macro.php:25
getTag()
Gets the tag name associated with this token parser.
Definition: Macro.php:54
decideBlockEnd(Twig_Token $token)
Definition: Macro.php:49
Base class for all token parsers.
Definition: TokenParser.php:18
Represents a Token.
Definition: Token.php:21
const BLOCK_END_TYPE
Definition: Token.php:30
getLine()
Definition: Token.php:87
getValue()
Definition: Token.php:103
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
const NAME_TYPE
Definition: Token.php:32
if($format !==null) $name
Definition: metadata.php:146
$stream
PHP stream implementation.