1 | <?php |
||
17 | class Token { |
||
18 | |||
19 | const INVALID_TYPE = -1; |
||
20 | |||
21 | const INVALID_LINE = -1; |
||
22 | |||
23 | const INVALID_VALUE = null; |
||
24 | |||
25 | const INVALID_INDEX = -1; |
||
26 | |||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | protected $type = self::INVALID_TYPE; |
||
31 | |||
32 | /** |
||
33 | * @var string|null |
||
34 | */ |
||
35 | protected $value; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $line = self::INVALID_LINE; |
||
41 | |||
42 | /** |
||
43 | * Indicate position in current collection |
||
44 | * |
||
45 | * @var int |
||
46 | */ |
||
47 | protected $index = self::INVALID_INDEX; |
||
48 | |||
49 | |||
50 | /** |
||
51 | * You need to provide at least 3 elements |
||
52 | * |
||
53 | * @param array $data |
||
54 | * @throws Exception |
||
55 | */ |
||
56 | 504 | public function __construct(array $data = []) { |
|
61 | |||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 9 | public function __toString() { |
|
67 | 9 | return $this->assemble(); |
|
68 | } |
||
69 | |||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | 3 | public function assemble() : string { |
|
75 | 3 | return $this->value !== null ? (string) $this->value : ''; |
|
76 | } |
||
77 | |||
78 | |||
79 | /** |
||
80 | * @param array $data |
||
81 | * @return $this |
||
82 | * @throws Exception |
||
83 | */ |
||
84 | 450 | protected function setData(array $data) : self { |
|
109 | |||
110 | |||
111 | /** |
||
112 | * @return array |
||
113 | */ |
||
114 | 9 | public function getData() : array { |
|
117 | |||
118 | |||
119 | /** |
||
120 | * @param int $type |
||
121 | * @return $this |
||
122 | */ |
||
123 | 447 | public function setType(int $type) : self { |
|
127 | |||
128 | |||
129 | /** |
||
130 | * @return int |
||
131 | */ |
||
132 | 264 | public function getType() : int { |
|
135 | |||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | 6 | public function getTypeName() : string { |
|
143 | |||
144 | |||
145 | /** |
||
146 | * @return string|null |
||
147 | */ |
||
148 | 450 | public function getValue() { |
|
151 | |||
152 | |||
153 | /** |
||
154 | * @param string|int $value |
||
155 | * @throws InvalidArgumentException |
||
156 | * @return $this |
||
157 | */ |
||
158 | 459 | public function setValue($value) : self { |
|
167 | |||
168 | |||
169 | /** |
||
170 | * @return int |
||
171 | */ |
||
172 | 423 | public function getLine() : int { |
|
175 | |||
176 | |||
177 | /** |
||
178 | * @param int $line |
||
179 | * @return $this |
||
180 | */ |
||
181 | 444 | public function setLine(int $line) : self { |
|
185 | |||
186 | |||
187 | /** |
||
188 | * @return bool |
||
189 | */ |
||
190 | 438 | public function isValid() : bool { |
|
193 | |||
194 | |||
195 | /** |
||
196 | * Remove all data from token so this token become invalid |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | 66 | public function remove() : self { |
|
207 | |||
208 | |||
209 | /** |
||
210 | * Add part to the end of value |
||
211 | * |
||
212 | * @param string $part |
||
213 | * @return $this |
||
214 | * @throws Exception |
||
215 | */ |
||
216 | 9 | public function appendToValue($part) : self { |
|
226 | |||
227 | |||
228 | /** |
||
229 | * Add part to the begin of value |
||
230 | * |
||
231 | * @param string $part |
||
232 | * @return $this |
||
233 | * @throws Exception |
||
234 | */ |
||
235 | 12 | public function prependToValue($part) : self { |
|
245 | |||
246 | |||
247 | /** |
||
248 | * @return null|int |
||
249 | */ |
||
250 | 225 | public function getIndex() { |
|
253 | |||
254 | |||
255 | /** |
||
256 | * @param int $index |
||
257 | * @return $this |
||
258 | */ |
||
259 | 462 | public function setIndex(int $index) : self { |
|
263 | |||
264 | 459 | public function equal(Token $token) : bool { |
|
271 | |||
272 | } |