Use composer metadata as primary source for version and ping build
This commit is contained in:
@@ -9,12 +9,39 @@ class VersionController extends Controller
|
||||
{
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
$version = Setting::where('key', 'version')->value('value');
|
||||
$build = Setting::where('key', 'build')->value('value');
|
||||
$composer = $this->readComposerMetadata();
|
||||
$version = $composer['version'] ?? Setting::where('key', 'version')->value('value');
|
||||
$build = $composer['build'] ?? Setting::where('key', 'build')->value('value');
|
||||
|
||||
return response()->json([
|
||||
'version' => $version,
|
||||
'build' => $build !== null ? (int) $build : null,
|
||||
]);
|
||||
}
|
||||
|
||||
private function readComposerMetadata(): array
|
||||
{
|
||||
$path = base_path('composer.json');
|
||||
if (!is_file($path) || !is_readable($path)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$raw = file_get_contents($path);
|
||||
if ($raw === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = json_decode($raw, true);
|
||||
if (!is_array($data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$version = trim((string) ($data['version'] ?? ''));
|
||||
$build = trim((string) ($data['build'] ?? ''));
|
||||
|
||||
return [
|
||||
'version' => $version !== '' ? $version : null,
|
||||
'build' => ctype_digit($build) ? (int) $build : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user