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
;
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>
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';
38 public function __construct(?
string $type, ?
string $value, ?
int $position)
41 $this->value
= $value;
42 $this->position
= $position;
45 public function getType(): ?
int
50 public function getValue(): ?
string
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
) {
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
106 return sprintf('<%s "%s" at %s>', $this->type
, $this->value
, $this->position
);
109 return sprintf('<%s at %s>', $this->type
, $this->position
);