ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Block.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 * (c) Armin Ronacher
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
26{
27 public function parse(Twig_Token $token)
28 {
29 $lineno = $token->getLine();
30 $stream = $this->parser->getStream();
31 $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
32 if ($this->parser->hasBlock($name)) {
33 throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
34 }
35 $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno));
36 $this->parser->pushLocalScope();
37 $this->parser->pushBlockStack($name);
38
40 $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
41 if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
42 $value = $token->getValue();
43
44 if ($value != $name) {
45 throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
46 }
47 }
48 } else {
49 $body = new Twig_Node(array(
50 new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
51 ));
52 }
54
55 $block->setNode('body', $body);
56 $this->parser->popBlockStack();
57 $this->parser->popLocalScope();
58
59 return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
60 }
61
63 {
64 return $token->test('endblock');
65 }
66
67 public function getTag()
68 {
69 return 'block';
70 }
71}
72
73class_alias('Twig_TokenParser_Block', 'Twig\TokenParser\BlockTokenParser', 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 block call node.
Represents a block node.
Definition: Block.php:19
Represents a node that outputs an expression.
Definition: Print.php:19
Represents a node in the AST.
Definition: Node.php:19
Marks a section of a template as being reusable.
Definition: Block.php:26
getTag()
Gets the tag name associated with this token parser.
Definition: Block.php:67
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Block.php:27
decideBlockEnd(Twig_Token $token)
Definition: Block.php:62
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
$stream
PHP stream implementation.