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
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
70class_alias('Twig_TokenParser_Use', 'Twig\TokenParser\UseTokenParser', false);
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 a node in the AST.
Definition: Node.php:19
Imports blocks defined in another template into the current template.
Definition: Use.php:29
getTag()
Gets the tag name associated with this token parser.
Definition: Use.php:64
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Use.php:30
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
const NAME_TYPE
Definition: Token.php:32
const PUNCTUATION_TYPE
Definition: Token.php:36
$template
$stream
PHP stream implementation.