PEEL Shopping
Open source ecommerce : PEEL Shopping
Set.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  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
30 {
38  public function parse(Twig_Token $token)
39  {
40  $lineno = $token->getLine();
41  $stream = $this->parser->getStream();
42  $names = $this->parser->getExpressionParser()->parseAssignmentExpression();
43 
44  $capture = false;
45  if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) {
46  $stream->next();
47  $values = $this->parser->getExpressionParser()->parseMultitargetExpression();
48 
49  $stream->expect(Twig_Token::BLOCK_END_TYPE);
50 
51  if (count($names) !== count($values)) {
52  throw new Twig_Error_Syntax("When using set, you must have the same number of variables and assignments.", $stream->getCurrent()->getLine(), $stream->getFilename());
53  }
54  } else {
55  $capture = true;
56 
57  if (count($names) > 1) {
58  throw new Twig_Error_Syntax("When using set with a block, you cannot have a multi-target.", $stream->getCurrent()->getLine(), $stream->getFilename());
59  }
60 
61  $stream->expect(Twig_Token::BLOCK_END_TYPE);
62 
63  $values = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
64  $stream->expect(Twig_Token::BLOCK_END_TYPE);
65  }
66 
67  return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag());
68  }
69 
70  public function decideBlockEnd(Twig_Token $token)
71  {
72  return $token->test('endset');
73  }
74 
80  public function getTag()
81  {
82  return 'set';
83  }
84 }
Base class for all token parsers.
Definition: TokenParser.php:17
const OPERATOR_TYPE
Definition: Token.php:33
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Defines a variable.
Definition: Set.php:29
const BLOCK_END_TYPE
Definition: Token.php:28
Represents a Token.
Definition: Token.php:18
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
Represents a set node.
Definition: Set.php:17
decideBlockEnd(Twig_Token $token)
Definition: Set.php:70
getTag()
Gets the tag name associated with this token parser.
Definition: Set.php:80
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Set.php:38

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