ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_TokenParser_From Class Reference

Imports macros. More...

+ Inheritance diagram for Twig_TokenParser_From:
+ Collaboration diagram for Twig_TokenParser_From:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 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...
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Imports macros.

  {% from 'forms.html' import forms %}

Definition at line 21 of file From.php.

Member Function Documentation

◆ getTag()

Twig_TokenParser_From::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 60 of file From.php.

Referenced by parse().

61  {
62  return 'from';
63  }
+ Here is the caller graph for this function:

◆ parse()

Twig_TokenParser_From::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 23 of file From.php.

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

24  {
25  $macro = $this->parser->getExpressionParser()->parseExpression();
26  $stream = $this->parser->getStream();
27  $stream->expect('import');
28 
29  $targets = array();
30  do {
31  $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
32 
33  $alias = $name;
34  if ($stream->nextIf('as')) {
35  $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
36  }
37 
38  $targets[$name] = $alias;
39 
40  if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
41  break;
42  }
43  } while (true);
44 
46 
47  $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
48 
49  foreach ($targets as $name => $alias) {
50  if ($this->parser->isReservedMacroName($name)) {
51  throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
52  }
53 
54  $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var'));
55  }
56 
57  return $node;
58  }
const PUNCTUATION_TYPE
Definition: Token.php:36
$stream
PHP stream implementation.
getTag()
Gets the tag name associated with this token parser.
Definition: From.php:60
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Represents an import node.
Definition: Import.php:17
getLine()
Definition: Token.php:87
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30
+ Here is the call graph for this function:

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