This repository was archived by the owner on Mar 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVersion.php
More file actions
68 lines (58 loc) · 1.32 KB
/
Version.php
File metadata and controls
68 lines (58 loc) · 1.32 KB
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
<?php
namespace Sencha\ExtJsBundle;
final class Version
{
/**
* ExtJS version identification
*/
const VERSION = '4.1.0-beta-1';
/**
* Constants of version parts
*/
const PART_MAJOR = 'major';
const PART_MINOR = 'minor';
const PART_MINI = 'mini';
const PART_SUFFIX = 'suffix';
/**
* Reverse map of version parts
*
* @var array
*/
private static $reverseMap = array(
'major' => 1,
'minor' => 2,
'mini' => 3,
'suffix' => 4,
);
/**
* Gets the version
*
* If $part is null, the entire version is returned. If it is a string,
* the version part is returned. If a part is given and $fromBeginning is
* set to true, the version is returned from the beginning to the named
* part.
*
* @param string $part
* @param boolean $fromBeginning
*
* @return string
*/
public static function getVersion($part = null, $fromBeginning = false)
{
if (is_null($part)) {
return self::VERSION;
}
if (preg_match('(^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<mini>\d+)(?P<suffix>.*)?$)', self::VERSION, $matches)) {
if ($fromBeginning == false) {
return $matches[$part];
} else {
$version = '';
for ($i = 1; $i <= self::$reverseMap[$part]; ++$i) {
$version .= ( ($i > 1 && $i < 4) ? '.' : '') . $matches[$i];
}
return $version;
}
}
return '';
}
}