ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_TokenParser_Macro Class Reference

Defines a macro. More...

+ Inheritance diagram for Twig_TokenParser_Macro:
+ Collaboration diagram for Twig_TokenParser_Macro:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 decideBlockEnd (Twig_Token $token)
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 
- Public Member Functions inherited from Twig_TokenParser
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Defines a macro.

{% macro input(name, value, type, size) %}
   <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" >
{% endmacro %}

@final

Definition at line 23 of file Macro.php.

Member Function Documentation

◆ decideBlockEnd()

Twig_TokenParser_Macro::decideBlockEnd ( Twig_Token  $token)

Definition at line 49 of file Macro.php.

50 {
51 return $token->test('endmacro');
52 }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70

References Twig_Token\test().

+ Here is the call graph for this function:

◆ getTag()

Twig_TokenParser_Macro::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 54 of file Macro.php.

55 {
56 return 'macro';
57 }

Referenced by parse().

+ Here is the caller graph for this function:

◆ parse()

Twig_TokenParser_Macro::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 25 of file Macro.php.

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 }
sprintf('%.4f', $callTime)
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
getTag()
Gets the tag name associated with this token parser.
Definition: Macro.php:54
const BLOCK_END_TYPE
Definition: Token.php:30
getLine()
Definition: Token.php:87
getValue()
Definition: Token.php:103
const NAME_TYPE
Definition: Token.php:32
if($format !==null) $name
Definition: metadata.php:146
$stream
PHP stream implementation.

References $name, GuzzleHttp\Psr7\$stream, Twig_Token\BLOCK_END_TYPE, Twig_Token\getLine(), getTag(), Twig_Token\getValue(), Twig_Token\NAME_TYPE, and sprintf.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: