forked from phalcon/cphalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.zep
204 lines (175 loc) · 4.19 KB
/
version.zep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalconphp.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon;
/**
* Phalcon\Version
*
* This class allows to get the installed version of the framework
*/
class Version
{
/**
* The constant referencing the major version. Returns 0
*
* <code>
* echo Phalcon\Version::getPart(
* Phalcon\Version::VERSION_MAJOR
* );
* </code>
*/
const VERSION_MAJOR = 0;
/**
* The constant referencing the major version. Returns 1
*
* <code>
* echo Phalcon\Version::getPart(
* Phalcon\Version::VERSION_MEDIUM
* );
* </code>
*/
const VERSION_MEDIUM = 1;
/**
* The constant referencing the major version. Returns 2
*
* <code>
* echo Phalcon\Version::getPart(
* Phalcon\Version::VERSION_MINOR
* );
* </code>
*/
const VERSION_MINOR = 2;
/**
* The constant referencing the major version. Returns 3
*
* <code>
* echo Phalcon\Version::getPart(
* Phalcon\Version::VERSION_SPECIAL
* );
* </code>
*/
const VERSION_SPECIAL = 3;
/**
* The constant referencing the major version. Returns 4
*
* <code>
* echo Phalcon\Version::getPart(
* Phalcon\Version::VERSION_SPECIAL_NUMBER
* );
* </code>
*/
const VERSION_SPECIAL_NUMBER = 4;
/**
* Area where the version number is set. The format is as follows:
* ABBCCDE
*
* A - Major version
* B - Med version (two digits)
* C - Min version (two digits)
* D - Special release: 1 = Alpha, 2 = Beta, 3 = RC, 4 = Stable
* E - Special release version i.e. RC1, Beta2 etc.
*/
protected static function _getVersion() -> array
{
return [4, 0, 0, 1, 0];
}
/**
* Translates a number to a special release
*
* If Special release = 1 this function will return ALPHA
*/
protected final static function _getSpecial(int special) -> string
{
var suffix = "";
switch special {
case 1:
let suffix = "ALPHA";
break;
case 2:
let suffix = "BETA";
break;
case 3:
let suffix = "RC";
break;
}
return suffix;
}
/**
* Returns the active version (string)
*
* <code>
* echo Phalcon\Version::get();
* </code>
*/
public static function get() -> string
{
var version, major, medium, minor,
special, specialNumber, result, suffix;
let version = static::_getVersion();
let major = version[self::VERSION_MAJOR],
medium = version[self::VERSION_MEDIUM],
minor = version[self::VERSION_MINOR],
special = version[self::VERSION_SPECIAL],
specialNumber = version[self::VERSION_SPECIAL_NUMBER];
let result = major . "." . medium . "." . minor . " ";
let suffix = static::_getSpecial(special);
if suffix != "" {
let result .= suffix . " " . specialNumber;
}
return trim(result);
}
/**
* Returns the numeric active version
*
* <code>
* echo Phalcon\Version::getId();
* </code>
*/
public static function getId() -> string
{
var version, major, medium, minor,
special, specialNumber;
let version = static::_getVersion();
let major = version[self::VERSION_MAJOR],
medium = version[self::VERSION_MEDIUM],
minor = version[self::VERSION_MINOR],
special = version[self::VERSION_SPECIAL],
specialNumber = version[self::VERSION_SPECIAL_NUMBER];
return major . sprintf("%02s", medium) . sprintf("%02s", minor) . special . specialNumber;
}
/**
* Returns a specific part of the version. If the wrong parameter is passed
* it will return the full version
*
* <code>
* echo Phalcon\Version::getPart(
* Phalcon\Version::VERSION_MAJOR
* );
* </code>
*/
public static function getPart(int part) -> string
{
var version, result;
let version = static::_getVersion();
switch part {
case self::VERSION_MAJOR:
case self::VERSION_MEDIUM:
case self::VERSION_MINOR:
case self::VERSION_SPECIAL_NUMBER:
let result = version[part];
break;
case self::VERSION_SPECIAL:
let result = static::_getSpecial(version[self::VERSION_SPECIAL]);
break;
default:
let result = static::get();
break;
}
return result;
}
}