Merge pull request #4036 from dokuwiki/issue4033
[dokuwiki.git] / _test / vendor / symfony / css-selector / Parser / Token.php
bloba053203c00103d9272af03c9e0f18a67faa716c8
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\CssSelector\Parser;
14 /**
15 * CSS selector token.
17 * This component is a port of the Python cssselect library,
18 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
20 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
22 * @internal
24 class Token
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';
34 private $type;
35 private $value;
36 private $position;
38 public function __construct(?string $type, ?string $value, ?int $position)
40 $this->type = $type;
41 $this->value = $value;
42 $this->position = $position;
45 public function getType(): ?int
47 return $this->type;
50 public function getValue(): ?string
52 return $this->value;
55 public function getPosition(): ?int
57 return $this->position;
60 public function isFileEnd(): bool
62 return self::TYPE_FILE_END === $this->type;
65 public function isDelimiter(array $values = []): bool
67 if (self::TYPE_DELIMITER !== $this->type) {
68 return false;
71 if (empty($values)) {
72 return true;
75 return \in_array($this->value, $values);
78 public function isWhitespace(): bool
80 return self::TYPE_WHITESPACE === $this->type;
83 public function isIdentifier(): bool
85 return self::TYPE_IDENTIFIER === $this->type;
88 public function isHash(): bool
90 return self::TYPE_HASH === $this->type;
93 public function isNumber(): bool
95 return self::TYPE_NUMBER === $this->type;
98 public function isString(): bool
100 return self::TYPE_STRING === $this->type;
103 public function __toString(): string
105 if ($this->value) {
106 return sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position);
109 return sprintf('<%s at %s>', $this->type, $this->position);