68fac59b03a32bb4f70b0ce17515fdaaa42f3418
[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     /**
35      * @var int
36      */
37     private $type;
38
39     /**
40      * @var string
41      */
42     private $value;
43
44     /**
45      * @var int
46      */
47     private $position;
48
49     /**
50      * @param int    $type
51      * @param string $value
52      * @param int    $position
53      */
54     public function __construct($type, $value, $position)
55     {
56         $this->type = $type;
57         $this->value = $value;
58         $this->position = $position;
59     }
60
61     /**
62      * @return int
63      */
64     public function getType()
65     {
66         return $this->type;
67     }
68
69     /**
70      * @return string
71      */
72     public function getValue()
73     {
74         return $this->value;
75     }
76
77     /**
78      * @return int
79      */
80     public function getPosition()
81     {
82         return $this->position;
83     }
84
85     /**
86      * @return bool
87      */
88     public function isFileEnd()
89     {
90         return self::TYPE_FILE_END === $this->type;
91     }
92
93     /**
94      * @param array $values
95      *
96      * @return bool
97      */
98     public function isDelimiter(array $values = array())
99     {
100         if (self::TYPE_DELIMITER !== $this->type) {
101             return false;
102         }
103
104         if (empty($values)) {
105             return true;
106         }
107
108         return in_array($this->value, $values);
109     }
110
111     /**
112      * @return bool
113      */
114     public function isWhitespace()
115     {
116         return self::TYPE_WHITESPACE === $this->type;
117     }
118
119     /**
120      * @return bool
121      */
122     public function isIdentifier()
123     {
124         return self::TYPE_IDENTIFIER === $this->type;
125     }
126
127     /**
128      * @return bool
129      */
130     public function isHash()
131     {
132         return self::TYPE_HASH === $this->type;
133     }
134
135     /**
136      * @return bool
137      */
138     public function isNumber()
139     {
140         return self::TYPE_NUMBER === $this->type;
141     }
142
143     /**
144      * @return bool
145      */
146     public function isString()
147     {
148         return self::TYPE_STRING === $this->type;
149     }
150
151     /**
152      * @return string
153      */
154     public function __toString()
155     {
156         if ($this->value) {
157             return sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position);
158         }
159
160         return sprintf('<%s at %s>', $this->type, $this->position);
161     }
162 }