PEEL Shopping
Open source ecommerce : PEEL Shopping
Block.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2009 Fabien Potencier
7  * (c) 2009 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 
24 {
32  public function parse(Twig_Token $token)
33  {
34  $lineno = $token->getLine();
35  $stream = $this->parser->getStream();
36  $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
37  if ($this->parser->hasBlock($name)) {
38  throw new Twig_Error_Syntax(sprintf("The block '$name' has already been defined line %d", $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename());
39  }
40  $this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno));
41  $this->parser->pushLocalScope();
42  $this->parser->pushBlockStack($name);
43 
44  if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
45  $stream->next();
46 
47  $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
48  if ($stream->test(Twig_Token::NAME_TYPE)) {
49  $value = $stream->next()->getValue();
50 
51  if ($value != $name) {
52  throw new Twig_Error_Syntax(sprintf("Expected endblock for block '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename());
53  }
54  }
55  } else {
56  $body = new Twig_Node(array(
57  new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
58  ));
59  }
60  $stream->expect(Twig_Token::BLOCK_END_TYPE);
61 
62  $block->setNode('body', $body);
63  $this->parser->popBlockStack();
64  $this->parser->popLocalScope();
65 
66  return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
67  }
68 
69  public function decideBlockEnd(Twig_Token $token)
70  {
71  return $token->test('endblock');
72  }
73 
79  public function getTag()
80  {
81  return 'block';
82  }
83 }
Represents a block node.
Definition: Block.php:18
Base class for all token parsers.
Definition: TokenParser.php:17
setNode($name, $node=null)
Sets a node.
Definition: Node.php:202
Represents a node in the AST.
Definition: Node.php:18
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Represents a block call node.
getTag()
Gets the tag name associated with this token parser.
Definition: Block.php:79
const BLOCK_END_TYPE
Definition: Token.php:28
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Block.php:32
decideBlockEnd(Twig_Token $token)
Definition: Block.php:69
Represents a Token.
Definition: Token.php:18
const NAME_TYPE
Definition: Token.php:30
getLine()
Gets the line.
Definition: Token.php:94
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:75
Marks a section of a template as being reusable.
Definition: Block.php:23
Represents a node that outputs an expression.
Definition: Print.php:18

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:18 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.