Skip to content

Commit 46b2460

Browse files
committed
fix: cache version variable
1 parent 54c1e51 commit 46b2460

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Info.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,31 @@ class Info
2828
public const TRAP_ROOT = __DIR__ . '/..';
2929
private const VERSION = 'experimental';
3030

31+
private static ?string $cachedVersion = null;
32+
3133
public static function version(): string
3234
{
35+
if (self::$cachedVersion !== null) {
36+
return self::$cachedVersion;
37+
}
38+
3339
$versionPath = self::TRAP_ROOT . '/src/version.json';
3440
$versionContents = file_get_contents($versionPath);
3541

3642
if ($versionContents === false) {
37-
return self::VERSION;
43+
self::$cachedVersion = self::VERSION;
44+
return self::$cachedVersion;
3845
}
3946

4047
$versionData = json_decode($versionContents, true);
4148

4249
if (!is_array($versionData) || !isset($versionData['.']) || !is_string($versionData['.'])) {
43-
return self::VERSION;
50+
self::$cachedVersion = self::VERSION;
51+
return self::$cachedVersion;
4452
}
4553

46-
return $versionData['.'];
54+
self::$cachedVersion = $versionData['.'];
55+
56+
return self::$cachedVersion;
4757
}
4858
}

0 commit comments

Comments
 (0)