friendship ended with social-app. php is my new best friend
1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\CssSelector\Parser; 13 14/** 15 * CSS selector token. 16 * 17 * This component is a port of the Python cssselect library, 18 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. 19 * 20 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> 21 * 22 * @internal 23 */ 24class Token 25{ 26 public const TYPE_FILE_END = 'eof'; 27 public const TYPE_DELIMITER = 'delimiter'; 28 public const TYPE_WHITESPACE = 'whitespace'; 29 public const TYPE_IDENTIFIER = 'identifier'; 30 public const TYPE_HASH = 'hash'; 31 public const TYPE_NUMBER = 'number'; 32 public const TYPE_STRING = 'string'; 33 34 public function __construct( 35 private ?string $type, 36 private ?string $value, 37 private ?int $position, 38 ) { 39 } 40 41 public function getType(): ?int 42 { 43 return $this->type; 44 } 45 46 public function getValue(): ?string 47 { 48 return $this->value; 49 } 50 51 public function getPosition(): ?int 52 { 53 return $this->position; 54 } 55 56 public function isFileEnd(): bool 57 { 58 return self::TYPE_FILE_END === $this->type; 59 } 60 61 public function isDelimiter(array $values = []): bool 62 { 63 if (self::TYPE_DELIMITER !== $this->type) { 64 return false; 65 } 66 67 if (!$values) { 68 return true; 69 } 70 71 return \in_array($this->value, $values, true); 72 } 73 74 public function isWhitespace(): bool 75 { 76 return self::TYPE_WHITESPACE === $this->type; 77 } 78 79 public function isIdentifier(): bool 80 { 81 return self::TYPE_IDENTIFIER === $this->type; 82 } 83 84 public function isHash(): bool 85 { 86 return self::TYPE_HASH === $this->type; 87 } 88 89 public function isNumber(): bool 90 { 91 return self::TYPE_NUMBER === $this->type; 92 } 93 94 public function isString(): bool 95 { 96 return self::TYPE_STRING === $this->type; 97 } 98 99 public function __toString(): string 100 { 101 if ($this->value) { 102 return \sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position); 103 } 104 105 return \sprintf('<%s at %s>', $this->type, $this->position); 106 } 107}