PEEL Shopping
Open source ecommerce : PEEL Shopping
If.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 
27 {
35  public function parse(Twig_Token $token)
36  {
37  $lineno = $token->getLine();
38  $expr = $this->parser->getExpressionParser()->parseExpression();
39  $stream = $this->parser->getStream();
40  $stream->expect(Twig_Token::BLOCK_END_TYPE);
41  $body = $this->parser->subparse(array($this, 'decideIfFork'));
42  $tests = array($expr, $body);
43  $else = null;
44 
45  $end = false;
46  while (!$end) {
47  switch ($stream->next()->getValue()) {
48  case 'else':
49  $stream->expect(Twig_Token::BLOCK_END_TYPE);
50  $else = $this->parser->subparse(array($this, 'decideIfEnd'));
51  break;
52 
53  case 'elseif':
54  $expr = $this->parser->getExpressionParser()->parseExpression();
55  $stream->expect(Twig_Token::BLOCK_END_TYPE);
56  $body = $this->parser->subparse(array($this, 'decideIfFork'));
57  $tests[] = $expr;
58  $tests[] = $body;
59  break;
60 
61  case 'endif':
62  $end = true;
63  break;
64 
65  default:
66  throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
67  }
68  }
69 
70  $stream->expect(Twig_Token::BLOCK_END_TYPE);
71 
72  return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag());
73  }
74 
75  public function decideIfFork(Twig_Token $token)
76  {
77  return $token->test(array('elseif', 'else', 'endif'));
78  }
79 
80  public function decideIfEnd(Twig_Token $token)
81  {
82  return $token->test(array('endif'));
83  }
84 
90  public function getTag()
91  {
92  return 'if';
93  }
94 }
Base class for all token parsers.
Definition: TokenParser.php:17
Represents an if node.
Definition: If.php:18
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: If.php:35
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
decideIfEnd(Twig_Token $token)
Definition: If.php:80
getTag()
Gets the tag name associated with this token parser.
Definition: If.php:90
const BLOCK_END_TYPE
Definition: Token.php:28
Represents a Token.
Definition: Token.php:18
getLine()
Gets the line.
Definition: Token.php:94
decideIfFork(Twig_Token $token)
Definition: If.php:75
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:75
Tests a condition.
Definition: If.php:26

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.