ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Token.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
21{
22 protected $value;
23 protected $type;
24 protected $lineno;
25
26 const EOF_TYPE = -1;
27 const TEXT_TYPE = 0;
29 const VAR_START_TYPE = 2;
30 const BLOCK_END_TYPE = 3;
31 const VAR_END_TYPE = 4;
32 const NAME_TYPE = 5;
33 const NUMBER_TYPE = 6;
34 const STRING_TYPE = 7;
35 const OPERATOR_TYPE = 8;
39
45 public function __construct($type, $value, $lineno)
46 {
47 $this->type = $type;
48 $this->value = $value;
49 $this->lineno = $lineno;
50 }
51
52 public function __toString()
53 {
54 return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value);
55 }
56
70 public function test($type, $values = null)
71 {
72 if (null === $values && !is_int($type)) {
73 $values = $type;
75 }
76
77 return ($this->type === $type) && (
78 null === $values ||
79 (is_array($values) && in_array($this->value, $values)) ||
80 $this->value == $values
81 );
82 }
83
87 public function getLine()
88 {
89 return $this->lineno;
90 }
91
95 public function getType()
96 {
97 return $this->type;
98 }
99
103 public function getValue()
104 {
105 return $this->value;
106 }
107
116 public static function typeToString($type, $short = false)
117 {
118 switch ($type) {
119 case self::EOF_TYPE:
120 $name = 'EOF_TYPE';
121 break;
122 case self::TEXT_TYPE:
123 $name = 'TEXT_TYPE';
124 break;
126 $name = 'BLOCK_START_TYPE';
127 break;
129 $name = 'VAR_START_TYPE';
130 break;
132 $name = 'BLOCK_END_TYPE';
133 break;
135 $name = 'VAR_END_TYPE';
136 break;
137 case self::NAME_TYPE:
138 $name = 'NAME_TYPE';
139 break;
141 $name = 'NUMBER_TYPE';
142 break;
144 $name = 'STRING_TYPE';
145 break;
147 $name = 'OPERATOR_TYPE';
148 break;
150 $name = 'PUNCTUATION_TYPE';
151 break;
153 $name = 'INTERPOLATION_START_TYPE';
154 break;
156 $name = 'INTERPOLATION_END_TYPE';
157 break;
158 default:
159 throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
160 }
161
162 return $short ? $name : 'Twig_Token::'.$name;
163 }
164
172 public static function typeToEnglish($type)
173 {
174 switch ($type) {
175 case self::EOF_TYPE:
176 return 'end of template';
177 case self::TEXT_TYPE:
178 return 'text';
180 return 'begin of statement block';
182 return 'begin of print statement';
184 return 'end of statement block';
186 return 'end of print statement';
187 case self::NAME_TYPE:
188 return 'name';
190 return 'number';
192 return 'string';
194 return 'operator';
196 return 'punctuation';
198 return 'begin of string interpolation';
200 return 'end of string interpolation';
201 default:
202 throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
203 }
204 }
205}
206
207class_alias('Twig_Token', 'Twig\Token', false);
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Represents a Token.
Definition: Token.php:21
const INTERPOLATION_START_TYPE
Definition: Token.php:37
getType()
Definition: Token.php:95
__toString()
Definition: Token.php:52
const BLOCK_END_TYPE
Definition: Token.php:30
getLine()
Definition: Token.php:87
const EOF_TYPE
Definition: Token.php:26
const VAR_START_TYPE
Definition: Token.php:29
getValue()
Definition: Token.php:103
static typeToString($type, $short=false)
Returns the constant representation (internal) of a given type.
Definition: Token.php:116
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
const INTERPOLATION_END_TYPE
Definition: Token.php:38
const TEXT_TYPE
Definition: Token.php:27
const NUMBER_TYPE
Definition: Token.php:33
const BLOCK_START_TYPE
Definition: Token.php:28
static typeToEnglish($type)
Returns the English representation of a given type.
Definition: Token.php:172
const VAR_END_TYPE
Definition: Token.php:31
const NAME_TYPE
Definition: Token.php:32
const STRING_TYPE
Definition: Token.php:34
const PUNCTUATION_TYPE
Definition: Token.php:36
__construct($type, $value, $lineno)
Definition: Token.php:45
const OPERATOR_TYPE
Definition: Token.php:35
if($format !==null) $name
Definition: metadata.php:146