Token.php 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Common\Lexer;
  4. use UnitEnum;
  5. use function in_array;
  6. /**
  7. * @template T of UnitEnum|string|int
  8. * @template V of string|int
  9. */
  10. final class Token
  11. {
  12. /**
  13. * The string value of the token in the input string
  14. *
  15. * @readonly
  16. * @var V
  17. */
  18. public string|int $value;
  19. /**
  20. * The type of the token (identifier, numeric, string, input parameter, none)
  21. *
  22. * @readonly
  23. * @var T|null
  24. */
  25. public $type;
  26. /**
  27. * The position of the token in the input string
  28. *
  29. * @readonly
  30. */
  31. public int $position;
  32. /**
  33. * @param V $value
  34. * @param T|null $type
  35. */
  36. public function __construct(string|int $value, $type, int $position)
  37. {
  38. $this->value = $value;
  39. $this->type = $type;
  40. $this->position = $position;
  41. }
  42. /** @param T ...$types */
  43. public function isA(...$types): bool
  44. {
  45. return in_array($this->type, $types, true);
  46. }
  47. }