|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Deployer\Component\Version; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Stores and returns the version information. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Kevin Herrera <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
class Version |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The build metadata identifiers. |
|
14
|
|
|
* |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $build; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The major version number. |
|
21
|
|
|
* |
|
22
|
|
|
* @var integer |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $major; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The minor version number. |
|
28
|
|
|
* |
|
29
|
|
|
* @var integer |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $minor; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The patch version number. |
|
35
|
|
|
* |
|
36
|
|
|
* @var integer |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $patch; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The pre-release version identifiers. |
|
42
|
|
|
* |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $preRelease; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Sets the version information. |
|
49
|
|
|
* |
|
50
|
|
|
* @param integer $major The major version number. |
|
51
|
|
|
* @param integer $minor The minor version number. |
|
52
|
|
|
* @param integer $patch The patch version number. |
|
53
|
|
|
* @param array $pre The pre-release version identifiers. |
|
54
|
|
|
* @param array $build The build metadata identifiers. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct( |
|
57
|
|
|
$major = 0, |
|
58
|
|
|
$minor = 0, |
|
59
|
|
|
$patch = 0, |
|
60
|
|
|
array $pre = array(), |
|
61
|
|
|
array $build = array() |
|
62
|
|
|
) { |
|
63
|
|
|
$this->build = $build; |
|
64
|
|
|
$this->major = $major; |
|
65
|
|
|
$this->minor = $minor; |
|
66
|
|
|
$this->patch = $patch; |
|
67
|
|
|
$this->preRelease = $pre; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the build metadata identifiers. |
|
72
|
|
|
* |
|
73
|
|
|
* @return array The build metadata identifiers. |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getBuild() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->build; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Returns the major version number. |
|
82
|
|
|
* |
|
83
|
|
|
* @return integer The major version number. |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getMajor() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->major; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the minor version number. |
|
92
|
|
|
* |
|
93
|
|
|
* @return integer The minor version number. |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getMinor() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->minor; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Returns the patch version number. |
|
102
|
|
|
* |
|
103
|
|
|
* @return integer The patch version number. |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getPatch() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->patch; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Returns the pre-release version identifiers. |
|
112
|
|
|
* |
|
113
|
|
|
* @return array The pre-release version identifiers. |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getPreRelease() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->preRelease; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Checks if the version number is stable. |
|
122
|
|
|
* |
|
123
|
|
|
* @return boolean TRUE if it is stable, FALSE if not. |
|
124
|
|
|
*/ |
|
125
|
|
|
public function isStable() |
|
126
|
|
|
{ |
|
127
|
|
|
return empty($this->preRelease) && $this->major !== 0; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Returns string representation. |
|
132
|
|
|
* |
|
133
|
|
|
* @return string The string representation. |
|
134
|
|
|
*/ |
|
135
|
|
|
public function __toString() |
|
136
|
|
|
{ |
|
137
|
|
|
return Dumper::toString($this); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|