|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: RocketCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 23.03.2018 |
|
25
|
|
|
* Time: 15:46 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
class Version { |
|
29
|
|
|
|
|
30
|
|
|
protected static $instance = null; |
|
31
|
|
|
|
|
32
|
|
|
protected $version_data = array(); |
|
33
|
|
|
|
|
34
|
|
|
public function __construct() { |
|
35
|
|
|
// |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function load ($version_path) { |
|
39
|
|
|
//because unserialize is 2 times faster than json_decode, we cache this value |
|
40
|
|
|
if (Cache::contains("version", "version_" . $version_path)) { |
|
41
|
|
|
$this->version_data = Cache::get("version", "version_" . $version_path); |
|
42
|
|
|
} else { |
|
43
|
|
|
if (!file_exists($version_path)) { |
|
44
|
|
|
echo "Version file doesnt exists: " . $version_path; |
|
45
|
|
|
exit; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$array = json_decode(file_get_contents($version_path), true); |
|
49
|
|
|
|
|
50
|
|
|
//cache |
|
51
|
|
|
Cache::put("version", "version_" . $version_path, $array); |
|
52
|
|
|
|
|
53
|
|
|
$this->version_data = $array; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getVersion () : string { |
|
58
|
|
|
if (!isset($this->version_data['version'])) { |
|
59
|
|
|
var_dump($this->version_data); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
echo "Version not found!"; |
|
62
|
|
|
exit; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->version_data['version']; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getBuildNumber () : string { |
|
69
|
|
|
return $this->version_data['build']; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public static function ¤t () : Version { |
|
73
|
|
|
if (self::$instance == null) { |
|
74
|
|
|
self::$instance = new Version(); |
|
75
|
|
|
self::$instance->load(ROOT_PATH . "system/core/version.json"); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return self::$instance; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
?> |
|
|
|
|
|
|
84
|
|
|
|