ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
66class_alias('Twig_TokenParser_From', 'Twig\TokenParser\FromTokenParser', 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 an import node.
Definition: Import.php:18
Imports macros.
Definition: From.php:22
getTag()
Gets the tag name associated with this token parser.
Definition: From.php:60
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: From.php:23
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
const NAME_TYPE
Definition: Token.php:32
const PUNCTUATION_TYPE
Definition: Token.php:36
if($format !==null) $name
Definition: metadata.php:146
$stream
PHP stream implementation.