Handler
2 years ago
Shortcut
2 years ago
Tokenizer
2 years ago
Parser.php
2 years ago
ParserInterface.php
2 years ago
Reader.php
2 years ago
Token.php
2 years ago
TokenStream.php
2 years ago
index.php
2 years ago
Token.php
76 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\Parser; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class Token |
| 5 | { |
| 6 | public const TYPE_FILE_END = 'eof'; |
| 7 | public const TYPE_DELIMITER = 'delimiter'; |
| 8 | public const TYPE_WHITESPACE = 'whitespace'; |
| 9 | public const TYPE_IDENTIFIER = 'identifier'; |
| 10 | public const TYPE_HASH = 'hash'; |
| 11 | public const TYPE_NUMBER = 'number'; |
| 12 | public const TYPE_STRING = 'string'; |
| 13 | private $type; |
| 14 | private $value; |
| 15 | private $position; |
| 16 | public function __construct(?string $type, ?string $value, ?int $position) |
| 17 | { |
| 18 | $this->type = $type; |
| 19 | $this->value = $value; |
| 20 | $this->position = $position; |
| 21 | } |
| 22 | public function getType() : ?int |
| 23 | { |
| 24 | return $this->type; |
| 25 | } |
| 26 | public function getValue() : ?string |
| 27 | { |
| 28 | return $this->value; |
| 29 | } |
| 30 | public function getPosition() : ?int |
| 31 | { |
| 32 | return $this->position; |
| 33 | } |
| 34 | public function isFileEnd() : bool |
| 35 | { |
| 36 | return self::TYPE_FILE_END === $this->type; |
| 37 | } |
| 38 | public function isDelimiter(array $values = []) : bool |
| 39 | { |
| 40 | if (self::TYPE_DELIMITER !== $this->type) { |
| 41 | return \false; |
| 42 | } |
| 43 | if (empty($values)) { |
| 44 | return \true; |
| 45 | } |
| 46 | return \in_array($this->value, $values); |
| 47 | } |
| 48 | public function isWhitespace() : bool |
| 49 | { |
| 50 | return self::TYPE_WHITESPACE === $this->type; |
| 51 | } |
| 52 | public function isIdentifier() : bool |
| 53 | { |
| 54 | return self::TYPE_IDENTIFIER === $this->type; |
| 55 | } |
| 56 | public function isHash() : bool |
| 57 | { |
| 58 | return self::TYPE_HASH === $this->type; |
| 59 | } |
| 60 | public function isNumber() : bool |
| 61 | { |
| 62 | return self::TYPE_NUMBER === $this->type; |
| 63 | } |
| 64 | public function isString() : bool |
| 65 | { |
| 66 | return self::TYPE_STRING === $this->type; |
| 67 | } |
| 68 | public function __toString() : string |
| 69 | { |
| 70 | if ($this->value) { |
| 71 | return \sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position); |
| 72 | } |
| 73 | return \sprintf('<%s at %s>', $this->type, $this->position); |
| 74 | } |
| 75 | } |
| 76 |