vendor/symfony/expression-language/Token.php line 54

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\ExpressionLanguage;
  11. /**
  12.  * Represents a Token.
  13.  *
  14.  * @author Fabien Potencier <fabien@symfony.com>
  15.  */
  16. class Token
  17. {
  18.     public $value;
  19.     public $type;
  20.     public $cursor;
  21.     public const EOF_TYPE 'end of expression';
  22.     public const NAME_TYPE 'name';
  23.     public const NUMBER_TYPE 'number';
  24.     public const STRING_TYPE 'string';
  25.     public const OPERATOR_TYPE 'operator';
  26.     public const PUNCTUATION_TYPE 'punctuation';
  27.     /**
  28.      * @param string $type   The type of the token (self::*_TYPE)
  29.      * @param int    $cursor The cursor position in the source
  30.      */
  31.     public function __construct(string $typestring|int|float|null $value, ?int $cursor)
  32.     {
  33.         $this->type $type;
  34.         $this->value $value;
  35.         $this->cursor $cursor;
  36.     }
  37.     /**
  38.      * Returns a string representation of the token.
  39.      */
  40.     public function __toString(): string
  41.     {
  42.         return sprintf('%3d %-11s %s'$this->cursorstrtoupper($this->type), $this->value);
  43.     }
  44.     /**
  45.      * Tests the current token for a type and/or a value.
  46.      */
  47.     public function test(string $typestring $value null): bool
  48.     {
  49.         return $this->type === $type && (null === $value || $this->value == $value);
  50.     }
  51. }