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