72baae776dab37072c8bd12a7222093bdeea470b
[yaffs-website] / vendor / symfony / css-selector / Parser / Token.php
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
12 namespace 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  */
24 class Token
25 {
26     const TYPE_FILE_END = 'eof';
27     const TYPE_DELIMITER = 'delimiter';
28     const TYPE_WHITESPACE = 'whitespace';
29     const TYPE_IDENTIFIER = 'identifier';
30     const TYPE_HASH = 'hash';
31     const TYPE_NUMBER = 'number';
32     const TYPE_STRING = 'string';
33
34     private $type;
35     private $value;
36     private $position;
37
38     /**
39      * @param int    $type
40      * @param string $value
41      * @param int    $position
42      */
43     public function __construct($type, $value, $position)
44     {
45         $this->type = $type;
46         $this->value = $value;
47         $this->position = $position;
48     }
49
50     /**
51      * @return int
52      */
53     public function getType()
54     {
55         return $this->type;
56     }
57
58     /**
59      * @return string
60      */
61     public function getValue()
62     {
63         return $this->value;
64     }
65
66     /**
67      * @return int
68      */
69     public function getPosition()
70     {
71         return $this->position;
72     }
73
74     /**
75      * @return bool
76      */
77     public function isFileEnd()
78     {
79         return self::TYPE_FILE_END === $this->type;
80     }
81
82     /**
83      * @return bool
84      */
85     public function isDelimiter(array $values = array())
86     {
87         if (self::TYPE_DELIMITER !== $this->type) {
88             return false;
89         }
90
91         if (empty($values)) {
92             return true;
93         }
94
95         return \in_array($this->value, $values);
96     }
97
98     /**
99      * @return bool
100      */
101     public function isWhitespace()
102     {
103         return self::TYPE_WHITESPACE === $this->type;
104     }
105
106     /**
107      * @return bool
108      */
109     public function isIdentifier()
110     {
111         return self::TYPE_IDENTIFIER === $this->type;
112     }
113
114     /**
115      * @return bool
116      */
117     public function isHash()
118     {
119         return self::TYPE_HASH === $this->type;
120     }
121
122     /**
123      * @return bool
124      */
125     public function isNumber()
126     {
127         return self::TYPE_NUMBER === $this->type;
128     }
129
130     /**
131      * @return bool
132      */
133     public function isString()
134     {
135         return self::TYPE_STRING === $this->type;
136     }
137
138     /**
139      * @return string
140      */
141     public function __toString()
142     {
143         if ($this->value) {
144             return sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position);
145         }
146
147         return sprintf('<%s at %s>', $this->type, $this->position);
148     }
149 }