Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Token.php
001 <?php
002
003 /*
004 * This file is part of Twig.
005 *
006 * (c) 2009 Fabien Potencier
007 * (c) 2009 Armin Ronacher
008 *
009 * For the full copyright and license information, please view the LICENSE
010 * file that was distributed with this source code.
011 */
012
013 /**
014 * Represents a Token.
015 *
016 * @author Fabien Potencier <fabien@symfony.com>
017 */
018 class Twig_Token
019 {
020 protected $value;
021 protected $type;
022 protected $lineno;
023
024 const EOF_TYPE = -1;
025 const TEXT_TYPE = 0;
026 const BLOCK_START_TYPE = 1;
027 const VAR_START_TYPE = 2;
028 const BLOCK_END_TYPE = 3;
029 const VAR_END_TYPE = 4;
030 const NAME_TYPE = 5;
031 const NUMBER_TYPE = 6;
032 const STRING_TYPE = 7;
033 const OPERATOR_TYPE = 8;
034 const PUNCTUATION_TYPE = 9;
035 const INTERPOLATION_START_TYPE = 10;
036 const INTERPOLATION_END_TYPE = 11;
037
038 /**
039 * Constructor.
040 *
041 * @param int $type The type of the token
042 * @param string $value The token value
043 * @param int $lineno The line position in the source
044 */
045 public function __construct($type, $value, $lineno)
046 {
047 $this->type = $type;
048 $this->value = $value;
049 $this->lineno = $lineno;
050 }
051
052 /**
053 * Returns a string representation of the token.
054 *
055 * @return string A string representation of the token
056 */
057 public function __toString()
058 {
059 return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value);
060 }
061
062 /**
063 * Tests the current token for a type and/or a value.
064 *
065 * Parameters may be:
066 * * just type
067 * * type and value (or array of possible values)
068 * * just value (or array of possible values) (NAME_TYPE is used as type)
069 *
070 * @param array|int $type The type to test
071 * @param array|string|null $values The token value
072 *
073 * @return bool
074 */
075 public function test($type, $values = null)
076 {
077 if (null === $values && !is_int($type)) {
078 $values = $type;
079 $type = self::NAME_TYPE;
080 }
081
082 return ($this->type === $type) && (
083 null === $values ||
084 (is_array($values) && in_array($this->value, $values)) ||
085 $this->value == $values
086 );
087 }
088
089 /**
090 * Gets the line.
091 *
092 * @return int The source line
093 */
094 public function getLine()
095 {
096 return $this->lineno;
097 }
098
099 /**
100 * Gets the token type.
101 *
102 * @return int The token type
103 */
104 public function getType()
105 {
106 return $this->type;
107 }
108
109 /**
110 * Gets the token value.
111 *
112 * @return string The token value
113 */
114 public function getValue()
115 {
116 return $this->value;
117 }
118
119 /**
120 * Returns the constant representation (internal) of a given type.
121 *
122 * @param int $type The type as an integer
123 * @param bool $short Whether to return a short representation or not
124 *
125 * @return string The string representation
126 */
127 public static function typeToString($type, $short = false)
128 {
129 switch ($type) {
130 case self::EOF_TYPE:
131 $name = 'EOF_TYPE';
132 break;
133 case self::TEXT_TYPE:
134 $name = 'TEXT_TYPE';
135 break;
136 case self::BLOCK_START_TYPE:
137 $name = 'BLOCK_START_TYPE';
138 break;
139 case self::VAR_START_TYPE:
140 $name = 'VAR_START_TYPE';
141 break;
142 case self::BLOCK_END_TYPE:
143 $name = 'BLOCK_END_TYPE';
144 break;
145 case self::VAR_END_TYPE:
146 $name = 'VAR_END_TYPE';
147 break;
148 case self::NAME_TYPE:
149 $name = 'NAME_TYPE';
150 break;
151 case self::NUMBER_TYPE:
152 $name = 'NUMBER_TYPE';
153 break;
154 case self::STRING_TYPE:
155 $name = 'STRING_TYPE';
156 break;
157 case self::OPERATOR_TYPE:
158 $name = 'OPERATOR_TYPE';
159 break;
160 case self::PUNCTUATION_TYPE:
161 $name = 'PUNCTUATION_TYPE';
162 break;
163 case self::INTERPOLATION_START_TYPE:
164 $name = 'INTERPOLATION_START_TYPE';
165 break;
166 case self::INTERPOLATION_END_TYPE:
167 $name = 'INTERPOLATION_END_TYPE';
168 break;
169 default:
170 throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
171 }
172
173 return $short ? $name : 'Twig_Token::'.$name;
174 }
175
176 /**
177 * Returns the english representation of a given type.
178 *
179 * @param int $type The type as an integer
180 *
181 * @return string The string representation
182 */
183 public static function typeToEnglish($type)
184 {
185 switch ($type) {
186 case self::EOF_TYPE:
187 return 'end of template';
188 case self::TEXT_TYPE:
189 return 'text';
190 case self::BLOCK_START_TYPE:
191 return 'begin of statement block';
192 case self::VAR_START_TYPE:
193 return 'begin of print statement';
194 case self::BLOCK_END_TYPE:
195 return 'end of statement block';
196 case self::VAR_END_TYPE:
197 return 'end of print statement';
198 case self::NAME_TYPE:
199 return 'name';
200 case self::NUMBER_TYPE:
201 return 'number';
202 case self::STRING_TYPE:
203 return 'string';
204 case self::OPERATOR_TYPE:
205 return 'operator';
206 case self::PUNCTUATION_TYPE:
207 return 'punctuation';
208 case self::INTERPOLATION_START_TYPE:
209 return 'begin of string interpolation';
210 case self::INTERPOLATION_END_TYPE:
211 return 'end of string interpolation';
212 default:
213 throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
214 }
215 }
216 }
217