File tree 1 file changed +13
-3
lines changed
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -28,21 +28,31 @@ class Info
28
28
public const TRAP_ROOT = __DIR__ . '/.. ' ;
29
29
private const VERSION = 'experimental ' ;
30
30
31
+ private static ?string $ cachedVersion = null ;
32
+
31
33
public static function version (): string
32
34
{
35
+ if (self ::$ cachedVersion !== null ) {
36
+ return self ::$ cachedVersion ;
37
+ }
38
+
33
39
$ versionPath = self ::TRAP_ROOT . '/src/version.json ' ;
34
40
$ versionContents = file_get_contents ($ versionPath );
35
41
36
42
if ($ versionContents === false ) {
37
- return self ::VERSION ;
43
+ self ::$ cachedVersion = self ::VERSION ;
44
+ return self ::$ cachedVersion ;
38
45
}
39
46
40
47
$ versionData = json_decode ($ versionContents , true );
41
48
42
49
if (!is_array ($ versionData ) || !isset ($ versionData ['. ' ]) || !is_string ($ versionData ['. ' ])) {
43
- return self ::VERSION ;
50
+ self ::$ cachedVersion = self ::VERSION ;
51
+ return self ::$ cachedVersion ;
44
52
}
45
53
46
- return $ versionData ['. ' ];
54
+ self ::$ cachedVersion = $ versionData ['. ' ];
55
+
56
+ return self ::$ cachedVersion ;
47
57
}
48
58
}
You can’t perform that action at this time.
0 commit comments