ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Use.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 
29 {
30  public function parse(Twig_Token $token)
31  {
32  $template = $this->parser->getExpressionParser()->parseExpression();
33  $stream = $this->parser->getStream();
34 
35  if (!$template instanceof Twig_Node_Expression_Constant) {
36  throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
37  }
38 
39  $targets = array();
40  if ($stream->nextIf('with')) {
41  do {
42  $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
43 
44  $alias = $name;
45  if ($stream->nextIf('as')) {
46  $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
47  }
48 
49  $targets[$name] = new Twig_Node_Expression_Constant($alias, -1);
50 
51  if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
52  break;
53  }
54  } while (true);
55  }
56 
58 
59  $this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
60 
61  return new Twig_Node();
62  }
63 
64  public function getTag()
65  {
66  return 'use';
67  }
68 }
69 
70 class_alias('Twig_TokenParser_Use', 'Twig\TokenParser\UseTokenParser', false);
const PUNCTUATION_TYPE
Definition: Token.php:36
Represents a node in the AST.
Definition: Node.php:18
$template
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Base class for all token parsers.
Definition: TokenParser.php:17
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Use.php:30
getTag()
Gets the tag name associated with this token parser.
Definition: Use.php:64
Imports blocks defined in another template into the current template.
Definition: Use.php:28
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30