1 | <?php |
||
2 | namespace phpbu\App; |
||
3 | |||
4 | use function array_slice; |
||
5 | use function explode; |
||
6 | use function implode; |
||
7 | |||
8 | /** |
||
9 | * Application Version. |
||
10 | * |
||
11 | * @package phpbu |
||
12 | * @subpackage App |
||
13 | * @author Sebastian Feldmann <[email protected]> |
||
14 | * @copyright Sebastian Feldmann <[email protected]> |
||
15 | * @license https://opensource.org/licenses/MIT The MIT License (MIT) |
||
16 | * @link http://phpbu.de/ |
||
17 | * @since Class available since Release 1.0.0 |
||
18 | * @internal |
||
19 | */ |
||
20 | final class Version |
||
21 | { |
||
22 | /** |
||
23 | * Current version |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private static $version; |
||
28 | |||
29 | /** |
||
30 | * Path to application root directory. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $path; |
||
35 | |||
36 | /** |
||
37 | * Current release version. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $release; |
||
42 | |||
43 | /** |
||
44 | * Current version number. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | private $number; |
||
49 | |||
50 | /** |
||
51 | * @param string $release |
||
52 | * @param string $path |
||
53 | */ |
||
54 | public function __construct($release, $path) |
||
55 | 3 | { |
|
56 | $this->release = $release; |
||
57 | 3 | $this->path = $path; |
|
58 | 3 | } |
|
59 | 3 | ||
60 | /** |
||
61 | * Return the full version number. |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | public function getVersionNumber() : string |
||
66 | 3 | { |
|
67 | if ($this->number === null) { |
||
68 | 3 | if (count(explode('.', $this->release)) == 3) { |
|
69 | 3 | $this->number = $this->release; |
|
70 | 1 | } else { |
|
71 | $this->number = $this->release . '-dev'; |
||
72 | 2 | } |
|
73 | } |
||
74 | return $this->number; |
||
75 | 3 | } |
|
76 | |||
77 | /** |
||
78 | * Return the current version of PHPUnit. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public static function id() : string |
||
83 | 5 | { |
|
84 | if (self::$version === null) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
85 | 5 | $version = new self('6.0', dirname(dirname(__DIR__))); |
|
86 | 1 | self::$version = $version->getVersionNumber(); |
|
87 | 1 | } |
|
88 | |||
89 | return self::$version; |
||
90 | 5 | } |
|
91 | |||
92 | /** |
||
93 | * Return the minor version number e.g. x.x, x.y, x.z |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public static function minor() : string |
||
98 | 3 | { |
|
99 | $version = explode('-', self::id())[0]; |
||
100 | 3 | return implode('.', array_slice(explode('.', $version), 0, 2)); |
|
101 | 3 | } |
|
102 | |||
103 | /** |
||
104 | * Return the version string. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public static function getVersionString() : string |
||
109 | 1 | { |
|
110 | return 'phpbu ' . self::id() . ' by Sebastian Feldmann and contributors.'; |
||
111 | 1 | } |
|
112 | } |
||
113 |