ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
From.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 
22 {
23  public function parse(Twig_Token $token)
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  }
59 
60  public function getTag()
61  {
62  return 'from';
63  }
64 }
65 
66 class_alias('Twig_TokenParser_From', 'Twig\TokenParser\FromTokenParser', false);
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
Imports macros.
Definition: From.php:21
Base class for all token parsers.
Definition: TokenParser.php:17
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: From.php:23
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