forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemChecker.php
More file actions
61 lines (46 loc) · 1.42 KB
/
SystemChecker.php
File metadata and controls
61 lines (46 loc) · 1.42 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
<?php
namespace App\Services;
/**
* 🤔 inspired by: https://github.com/ploi/roadmap/blob/main/app/Services/SystemChecker.php
*/
class SystemChecker
{
public $localVersion;
public $remoteVersion;
public string $cacheKeyLocal = 'speedtest-local-version';
public string $cacheKeyRemote = 'speedtest-remote-version';
public function getVersions(): self
{
$this->localVersion = trim($this->getLocalVersion());
$this->remoteVersion = trim($this->getRemoteVersion());
return $this;
}
public function getLocalVersion()
{
return config('speedtest.build_version');
}
public function getRemoteVersion()
{
return cache()->remember($this->cacheKeyRemote, now()->addDay(), function () {
return shell_exec('curl https://api.github.com/repos/alexjustesen/speedtest-tracker/releases/latest -s | grep \'"tag_name":\' | sed -E \'s/.*"([^"]+)".*/\1/\'');
});
}
public function isOutOfDate()
{
$this->getVersions();
return $this->localVersion != $this->remoteVersion;
}
public function flushVersionData()
{
try {
cache()->forget($this->cacheKeyLocal);
cache()->forget($this->cacheKeyRemote);
} catch (\Exception $exception) {
// fail silently, it's ok
}
}
public function getPhpVersion(): string
{
return phpversion();
}
}