PEEL Shopping
Open source ecommerce : PEEL Shopping
Token.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 
19 {
20  protected $value;
21  protected $type;
22  protected $lineno;
23 
24  const EOF_TYPE = -1;
25  const TEXT_TYPE = 0;
26  const BLOCK_START_TYPE = 1;
27  const VAR_START_TYPE = 2;
28  const BLOCK_END_TYPE = 3;
29  const VAR_END_TYPE = 4;
30  const NAME_TYPE = 5;
31  const NUMBER_TYPE = 6;
32  const STRING_TYPE = 7;
33  const OPERATOR_TYPE = 8;
34  const PUNCTUATION_TYPE = 9;
37 
45  public function __construct($type, $value, $lineno)
46  {
47  $this->type = $type;
48  $this->value = $value;
49  $this->lineno = $lineno;
50  }
51 
57  public function __toString()
58  {
59  return sprintf('%s(%s)', self::typeToString($this->type, true, $this->lineno), $this->value);
60  }
61 
75  public function test($type, $values = null)
76  {
77  if (null === $values && !is_int($type)) {
78  $values = $type;
79  $type = self::NAME_TYPE;
80  }
81 
82  return ($this->type === $type) && (
83  null === $values ||
84  (is_array($values) && in_array($this->value, $values)) ||
85  $this->value == $values
86  );
87  }
88 
94  public function getLine()
95  {
96  return $this->lineno;
97  }
98 
104  public function getType()
105  {
106  return $this->type;
107  }
108 
114  public function getValue()
115  {
116  return $this->value;
117  }
118 
128  public static function typeToString($type, $short = false, $line = -1)
129  {
130  switch ($type) {
131  case self::EOF_TYPE:
132  $name = 'EOF_TYPE';
133  break;
134  case self::TEXT_TYPE:
135  $name = 'TEXT_TYPE';
136  break;
137  case self::BLOCK_START_TYPE:
138  $name = 'BLOCK_START_TYPE';
139  break;
140  case self::VAR_START_TYPE:
141  $name = 'VAR_START_TYPE';
142  break;
143  case self::BLOCK_END_TYPE:
144  $name = 'BLOCK_END_TYPE';
145  break;
146  case self::VAR_END_TYPE:
147  $name = 'VAR_END_TYPE';
148  break;
149  case self::NAME_TYPE:
150  $name = 'NAME_TYPE';
151  break;
152  case self::NUMBER_TYPE:
153  $name = 'NUMBER_TYPE';
154  break;
155  case self::STRING_TYPE:
156  $name = 'STRING_TYPE';
157  break;
158  case self::OPERATOR_TYPE:
159  $name = 'OPERATOR_TYPE';
160  break;
161  case self::PUNCTUATION_TYPE:
162  $name = 'PUNCTUATION_TYPE';
163  break;
164  case self::INTERPOLATION_START_TYPE:
165  $name = 'INTERPOLATION_START_TYPE';
166  break;
167  case self::INTERPOLATION_END_TYPE:
168  $name = 'INTERPOLATION_END_TYPE';
169  break;
170  default:
171  throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
172  }
173 
174  return $short ? $name : 'Twig_Token::'.$name;
175  }
176 
185  public static function typeToEnglish($type, $line = -1)
186  {
187  switch ($type) {
188  case self::EOF_TYPE:
189  return 'end of template';
190  case self::TEXT_TYPE:
191  return 'text';
192  case self::BLOCK_START_TYPE:
193  return 'begin of statement block';
194  case self::VAR_START_TYPE:
195  return 'begin of print statement';
196  case self::BLOCK_END_TYPE:
197  return 'end of statement block';
198  case self::VAR_END_TYPE:
199  return 'end of print statement';
200  case self::NAME_TYPE:
201  return 'name';
202  case self::NUMBER_TYPE:
203  return 'number';
204  case self::STRING_TYPE:
205  return 'string';
206  case self::OPERATOR_TYPE:
207  return 'operator';
208  case self::PUNCTUATION_TYPE:
209  return 'punctuation';
210  case self::INTERPOLATION_START_TYPE:
211  return 'begin of string interpolation';
212  case self::INTERPOLATION_END_TYPE:
213  return 'end of string interpolation';
214  default:
215  throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
216  }
217  }
218 }
static typeToString($type, $short=false, $line=-1)
Returns the constant representation (internal) of a given type.
Definition: Token.php:128
const VAR_START_TYPE
Definition: Token.php:27
const OPERATOR_TYPE
Definition: Token.php:33
const INTERPOLATION_END_TYPE
Definition: Token.php:36
__construct($type, $value, $lineno)
Constructor.
Definition: Token.php:45
static typeToEnglish($type, $line=-1)
Returns the english representation of a given type.
Definition: Token.php:185
getType()
Gets the token type.
Definition: Token.php:104
__toString()
Returns a string representation of the token.
Definition: Token.php:57
const BLOCK_END_TYPE
Definition: Token.php:28
const INTERPOLATION_START_TYPE
Definition: Token.php:35
Represents a Token.
Definition: Token.php:18
const NAME_TYPE
Definition: Token.php:30
getLine()
Gets the line.
Definition: Token.php:94
getValue()
Gets the token value.
Definition: Token.php:114
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:75
const PUNCTUATION_TYPE
Definition: Token.php:34
const VAR_END_TYPE
Definition: Token.php:29
const TEXT_TYPE
Definition: Token.php:25
const NUMBER_TYPE
Definition: Token.php:31
const STRING_TYPE
Definition: Token.php:32
const BLOCK_START_TYPE
Definition: Token.php:26
const EOF_TYPE
Definition: Token.php:24

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.