Resources
2 years ago
Php80.php
2 years ago
PhpToken.php
2 years ago
bootstrap.php
4 years ago
index.php
3 years ago
PhpToken.php
59 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Polyfill\Php80; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class PhpToken implements \Stringable |
| 5 | { |
| 6 | public $id; |
| 7 | public $text; |
| 8 | public $line; |
| 9 | public $pos; |
| 10 | public function __construct(int $id, string $text, int $line = -1, int $position = -1) |
| 11 | { |
| 12 | $this->id = $id; |
| 13 | $this->text = $text; |
| 14 | $this->line = $line; |
| 15 | $this->pos = $position; |
| 16 | } |
| 17 | public function getTokenName() : ?string |
| 18 | { |
| 19 | if ('UNKNOWN' === ($name = \token_name($this->id))) { |
| 20 | $name = \strlen($this->text) > 1 || \ord($this->text) < 32 ? null : $this->text; |
| 21 | } |
| 22 | return $name; |
| 23 | } |
| 24 | public function is($kind) : bool |
| 25 | { |
| 26 | foreach ((array) $kind as $value) { |
| 27 | if (\in_array($value, [$this->id, $this->text], \true)) { |
| 28 | return \true; |
| 29 | } |
| 30 | } |
| 31 | return \false; |
| 32 | } |
| 33 | public function isIgnorable() : bool |
| 34 | { |
| 35 | return \in_array($this->id, [\T_WHITESPACE, \T_COMMENT, \T_DOC_COMMENT, \T_OPEN_TAG], \true); |
| 36 | } |
| 37 | public function __toString() : string |
| 38 | { |
| 39 | return (string) $this->text; |
| 40 | } |
| 41 | public static function tokenize(string $code, int $flags = 0) : array |
| 42 | { |
| 43 | $line = 1; |
| 44 | $position = 0; |
| 45 | $tokens = \token_get_all($code, $flags); |
| 46 | foreach ($tokens as $index => $token) { |
| 47 | if (\is_string($token)) { |
| 48 | $id = \ord($token); |
| 49 | $text = $token; |
| 50 | } else { |
| 51 | [$id, $text, $line] = $token; |
| 52 | } |
| 53 | $tokens[$index] = new static($id, $text, $line, $position); |
| 54 | $position += \strlen($text); |
| 55 | } |
| 56 | return $tokens; |
| 57 | } |
| 58 | } |
| 59 |