-
-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathPanelInfoTransformer.php
More file actions
53 lines (44 loc) · 1.44 KB
/
PanelInfoTransformer.php
File metadata and controls
53 lines (44 loc) · 1.44 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
<?php
namespace App\Transformers\Api\Application;
use App\Services\Helpers\SoftwareVersionService;
class PanelInfoTransformer extends BaseTransformer
{
private SoftwareVersionService $versionService;
public function handle(SoftwareVersionService $versionService): void
{
$this->versionService = $versionService;
}
public function getResourceName(): string
{
return 'panel';
}
/**
* @param null $model
*/
public function transform($model): array
{
$currentVersion = config('app.version', 'canary');
return [
'version' => $currentVersion,
'git_hash' => $this->getGitHash(),
'fqdn' => parse_url(config('app.url'), PHP_URL_HOST),
'url' => config('app.url'),
'timezone' => config('app.timezone'),
'latest_version' => $this->versionService->latestPanelVersion(),
'is_latest' => $this->versionService->isLatestPanel(),
];
}
private function getGitHash(): ?string
{
if (file_exists(base_path('.git/HEAD'))) {
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));
if (array_key_exists(1, $head)) {
$path = base_path('.git/' . trim($head[1]));
if (file_exists($path)) {
return substr(file_get_contents($path), 0, 7);
}
}
}
return null;
}
}