1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright (c) 2014-2017 brian ridley |
5
|
|
|
* @author brian ridley <[email protected]> |
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
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 ptlis\SemanticVersion\Parse; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A token from a version number. |
16
|
|
|
*/ |
17
|
|
|
final class Token |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* '0-9' Numeric component of a version number (may be part of the label e.g. the final digit of 1.2.7-alpha.2). |
21
|
|
|
*/ |
22
|
|
|
const DIGITS = 'digits'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* '*' Wildcard numeric component of a version number (1.2.*). |
26
|
|
|
*/ |
27
|
|
|
const WILDCARD_DIGITS = 'wildcard-digits'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* '-' Contextually either a version range or label separator. |
31
|
|
|
*/ |
32
|
|
|
const DASH_SEPARATOR = 'dash-separator'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* '.' Separator between version components. |
36
|
|
|
*/ |
37
|
|
|
const DOT_SEPARATOR = 'dot-separator'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* '~' Specifies a strict range match (patch version increments only) against the subsequent version number. |
41
|
|
|
* |
42
|
|
|
* E.g. the version number ~1.7.3 is equivalent to >=1.7.3 <1.8.0 |
43
|
|
|
*/ |
44
|
|
|
const TILDE_RANGE = 'strict-range'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* '^' Specifies loose range match (minor & patch version increments) against the subsequent version number. |
48
|
|
|
* |
49
|
|
|
* E.g. the version number ^1.7.3 is equivalent to >=1.7.3 <2.0.0 |
50
|
|
|
*/ |
51
|
|
|
const CARET_RANGE = 'loose-range'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* 'a-zA-Z0-9' The string component of a label. |
55
|
|
|
*/ |
56
|
|
|
const LABEL_STRING = 'label-string'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Comparator for matching version number. |
60
|
|
|
*/ |
61
|
|
|
const EQUAL_TO = 'comparator-equal-to'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Greater than comparator. |
65
|
|
|
*/ |
66
|
|
|
const GREATER_THAN = 'comparator-greater-than'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Greater than or equal to comparator. |
70
|
|
|
*/ |
71
|
|
|
const GREATER_THAN_EQUAL = 'comparator-greater-than-equal-to'; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Less than comparator. |
75
|
|
|
*/ |
76
|
|
|
const LESS_THAN = 'comparator-less-than'; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Less than or equal to comparator. |
80
|
|
|
*/ |
81
|
|
|
const LESS_THAN_EQUAL = 'comparator-less-than-equal-to'; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Logical and between two constraints. |
85
|
|
|
*/ |
86
|
|
|
const LOGICAL_AND = 'and'; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Logical or between to constraints. |
90
|
|
|
*/ |
91
|
|
|
const LOGICAL_OR = 'or'; |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** @var string */ |
95
|
|
|
private $type; |
96
|
|
|
|
97
|
|
|
/** @var string */ |
98
|
|
|
private $value; |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Constructor. |
103
|
|
|
* |
104
|
|
|
* @param string $type One of class constants. |
105
|
|
|
* @param string $value |
106
|
|
|
*/ |
107
|
1 |
|
public function __construct($type, $value) |
108
|
|
|
{ |
109
|
1 |
|
$this->type = $type; |
110
|
1 |
|
$this->value = $value; |
111
|
1 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get the token type. |
115
|
|
|
* |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
1 |
|
public function getType() |
119
|
|
|
{ |
120
|
1 |
|
return $this->type; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get the token value. |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
1 |
|
public function getValue() |
129
|
|
|
{ |
130
|
1 |
|
return $this->value; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|