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 
60 class_alias('Twig_TokenParser_Macro', 'Twig\TokenParser\MacroTokenParser', false);
getTag()
Gets the tag name associated with this token parser.
Definition: Macro.php:54
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Represents a macro node.
Definition: Macro.php:17
Defines a macro.
Definition: Macro.php:23
if($format !==null) $name
Definition: metadata.php:146
Base class for all token parsers.
Definition: TokenParser.php:17
Represents a body node.
Definition: Body.php:17
getValue()
Definition: Token.php:103
Create styles array
The data for the language used.
decideBlockEnd(Twig_Token $token)
Definition: Macro.php:49
getLine()
Definition: Token.php:87
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Macro.php:25
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30